LCOV - code coverage report
Current view: top level - libreoffice/cui/source/tabpages - tpcolor.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 672 0.1 %
Date: 2012-12-17 Functions: 2 57 3.5 %
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 <tools/shl.hxx>
      21             : #include <tools/urlobj.hxx>
      22             : #include <unotools/pathoptions.hxx>
      23             : #include <sfx2/app.hxx>
      24             : #include <sfx2/module.hxx>
      25             : #include <sfx2/objsh.hxx>
      26             : #include <sfx2/viewsh.hxx>
      27             : #include <sfx2/viewfrm.hxx>
      28             : #include <sfx2/dispatch.hxx>
      29             : #include <svtools/colrdlg.hxx>
      30             : #include <vcl/msgbox.hxx>
      31             : #include <sfx2/filedlghelper.hxx>
      32             : #include <svx/ofaitem.hxx>
      33             : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
      34             : 
      35             : #define _SVX_TPCOLOR_CXX
      36             : 
      37             : #include <cuires.hrc>
      38             : #include "helpid.hrc"
      39             : #include "svx/xattr.hxx"
      40             : #include <svx/xpool.hxx>
      41             : #include <svx/xtable.hxx>
      42             : #include "svx/drawitem.hxx"
      43             : #include "cuitabarea.hxx"
      44             : #include "tabarea.hrc"
      45             : #include "defdlgname.hxx"
      46             : #include <svx/svxdlg.hxx>
      47             : #include <dialmgr.hxx>
      48             : #include <cuitabline.hxx>
      49             : #include <svx/dialmgr.hxx>
      50             : #include <svx/dialogs.hrc>
      51             : 
      52             : 
      53             : // Load save embed functionality
      54           0 : SvxLoadSaveEmbed::SvxLoadSaveEmbed( Window *pParent, Window *pDialog,
      55             :                                     const ResId &rLoad, const ResId &rSave,
      56             :                                     const ResId &rEmbed, const ResId &rTableName,
      57             :                                     XPropertyListType t, XOutdevItemPool* pXPool )
      58             :     : meType( t )
      59             :     , mpXPool( pXPool )
      60             :     , mpTopDlg( pDialog )
      61             :     , maBoxEmbed( pParent, rEmbed )
      62             :     , maBtnLoad( pParent, rLoad )
      63             :     , maBtnSave( pParent, rSave )
      64           0 :     , maTableName( pParent, rTableName )
      65             : {
      66           0 :     maBoxEmbed.SetToggleHdl( LINK( this, SvxLoadSaveEmbed, EmbedToggleHdl_Impl ) );
      67             : 
      68           0 :     maBtnLoad.SetClickHdl( LINK( this, SvxLoadSaveEmbed, ClickLoadHdl_Impl ) );
      69           0 :     maBtnSave.SetClickHdl( LINK( this, SvxLoadSaveEmbed, ClickSaveHdl_Impl ) );
      70             : 
      71           0 :     SetEmbed( GetEmbed() );
      72           0 :     UpdateTableName();
      73           0 : }
      74             : 
      75           0 : XPropertyListRef SvxLoadSaveEmbed::GetList()
      76             : {
      77           0 :     SvxAreaTabDialog* pArea = dynamic_cast< SvxAreaTabDialog* >( mpTopDlg );
      78           0 :     SvxLineTabDialog* pLine = dynamic_cast< SvxLineTabDialog* >( mpTopDlg );
      79             : 
      80           0 :     XColorListRef pList;
      81           0 :     if( pArea )
      82           0 :         pList = pArea->GetNewColorList();
      83           0 :     if( pLine )
      84           0 :         pList = pLine->GetNewColorList();
      85             : 
      86           0 :     if( !pList.is() ) {
      87           0 :         if( pArea )
      88           0 :             pList = pArea->GetColorList();
      89           0 :         if( pLine )
      90           0 :             pList = pLine->GetColorList();
      91             :     }
      92             : 
      93             :     // URGH - abstract this nicely ... for re-using SvxLoadSaveEmbed
      94           0 :     if( !pList.is() ) {
      95           0 :         SvxColorTabPage *pPage = dynamic_cast< SvxColorTabPage *>( this );
      96           0 :         if( pPage )
      97           0 :             pList = pPage->GetColorList();
      98             :     }
      99             : 
     100           0 :     return XPropertyListRef( static_cast< XPropertyList * >( pList.get() ) );
     101             : }
     102             : 
     103           0 : void SvxLoadSaveEmbed::SetEmbed( bool bEmbed )
     104             : {
     105           0 :     XPropertyListRef pList = GetList();
     106           0 :     if( pList.is() )
     107           0 :         pList->SetEmbedInDocument( bEmbed );
     108           0 :     maBoxEmbed.Check( bEmbed );
     109           0 : }
     110             : 
     111           0 : bool SvxLoadSaveEmbed::GetEmbed()
     112             : {
     113           0 :     XPropertyListRef pList = GetList();
     114           0 :     return pList.is() ? pList->IsEmbedInDocument() : 0;
     115             : }
     116             : 
     117           0 : IMPL_LINK_NOARG(SvxLoadSaveEmbed, EmbedToggleHdl_Impl)
     118             : {
     119           0 :     SetEmbed( maBoxEmbed.IsChecked() );
     120           0 :     return 0;
     121             : }
     122             : 
     123           0 : void SvxLoadSaveEmbed::HideLoadSaveEmbed()
     124             : {
     125           0 :     maBtnLoad.Hide();
     126           0 :     maBtnSave.Hide();
     127           0 :     maBoxEmbed.Hide();
     128           0 : }
     129             : 
     130           0 : void SvxLoadSaveEmbed::UpdateTableName()
     131             : {
     132             :     // Truncate the name if necessary ...
     133           0 :     String aString( CUI_RES( RID_SVXSTR_TABLE ) );
     134           0 :     aString.AppendAscii( ": " );
     135             : 
     136           0 :     XPropertyListRef pList = GetList();
     137           0 :     if( !pList.is() )
     138           0 :         return;
     139             : 
     140           0 :     INetURLObject aURL( pList->GetPath() );
     141           0 :     aURL.Append( pList->GetName() );
     142             : 
     143           0 :     if ( aURL.getBase().getLength() > 18 )
     144             :     {
     145           0 :         aString += String(aURL.getBase()).Copy( 0, 15 );
     146           0 :         aString.AppendAscii( "..." );
     147             :     }
     148             :     else
     149           0 :         aString += String (aURL.getBase());
     150             : 
     151           0 :     maTableName.SetText( aString );
     152             : }
     153             : 
     154             : // -----------------------------------------------------------------------
     155             : 
     156           0 : IMPL_LINK_NOARG(SvxLoadSaveEmbed, ClickLoadHdl_Impl)
     157             : {
     158           0 :     ResMgr& rMgr = CUI_MGR();
     159           0 :     sal_uInt16 nReturn = RET_YES;
     160           0 :     bool bLoaded = false;
     161             : 
     162           0 :     if( IsModified() && GetList()->Count() > 0 )
     163             :     {
     164             :         nReturn = WarningBox( mpTopDlg, WinBits( WB_YES_NO_CANCEL ),
     165           0 :                     String( ResId( RID_SVXSTR_WARN_TABLE_OVERWRITE, rMgr ) ) ).Execute();
     166             : 
     167           0 :         if ( nReturn == RET_YES )
     168           0 :             GetList()->Save();
     169             :     }
     170             : 
     171           0 :     if ( nReturn != RET_CANCEL )
     172             :     {
     173             :         ::sfx2::FileDialogHelper aDlg(
     174             :             css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
     175           0 :             0 );
     176           0 :         String aStrFilterType( XPropertyList::GetDefaultExtFilter( meType ) );
     177           0 :         aDlg.AddFilter( aStrFilterType, aStrFilterType );
     178             : 
     179           0 :         INetURLObject aFile( SvtPathOptions().GetPalettePath() );
     180           0 :         aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
     181             : 
     182           0 :         if ( aDlg.Execute() == ERRCODE_NONE )
     183             :         {
     184             :             XColorListRef pList = XPropertyList::CreatePropertyListFromURL(
     185           0 :                                         meType, aDlg.GetPath(), mpXPool )->AsColorList();
     186           0 :             if( pList->Load() )
     187             :             {
     188             :                 // check whether the table may be deleted:
     189           0 :                 SvxAreaTabDialog* pArea = dynamic_cast< SvxAreaTabDialog* >( mpTopDlg );
     190           0 :                 SvxLineTabDialog* pLine = dynamic_cast< SvxLineTabDialog* >( mpTopDlg );
     191             : 
     192             :                 // FIXME: want to have a generic set and get method by type ...
     193           0 :                 if( pArea )
     194           0 :                     pArea->SetNewColorList( pList );
     195           0 :                 else if( pLine )
     196           0 :                     pLine->SetNewColorList( pList );
     197             : 
     198           0 :                 bLoaded = true;
     199           0 :                 UpdateTableName();
     200             : 
     201           0 :                 AddState( CT_CHANGED );
     202           0 :                 SetModified( false );
     203           0 :                 SetEmbed( true );
     204             :             }
     205             :             else
     206             :             {
     207             :                 ErrorBox aErrorBox( mpTopDlg, WinBits( WB_OK ),
     208           0 :                     String( ResId( RID_SVXSTR_READ_DATA_ERROR, rMgr ) ) );
     209           0 :                 aErrorBox.Execute();
     210           0 :             }
     211           0 :         }
     212             :     }
     213           0 :     Update( bLoaded );
     214             : 
     215           0 :     return 0;
     216             : }
     217             : 
     218           0 : void SvxLoadSaveEmbed::EnableSave( bool bCanSave )
     219             : {
     220           0 :     if ( bCanSave )
     221           0 :         maBtnSave.Enable();
     222             :     else
     223           0 :         maBtnSave.Disable();
     224           0 : }
     225             : 
     226             : // -----------------------------------------------------------------------
     227             : 
     228           0 : IMPL_LINK_NOARG(SvxLoadSaveEmbed, ClickSaveHdl_Impl)
     229             : {
     230             :     ::sfx2::FileDialogHelper aDlg(
     231           0 :         css::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE, 0 );
     232             : 
     233           0 :     String aStrFilterType( XPropertyList::GetDefaultExtFilter( meType ) );
     234           0 :     aDlg.AddFilter( aStrFilterType, aStrFilterType );
     235             : 
     236           0 :     INetURLObject aFile( SvtPathOptions().GetPalettePath() );
     237             :     DBG_ASSERT( aFile.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     238             : 
     239           0 :     XPropertyListRef pList = GetList();
     240             : 
     241           0 :     if( pList->GetName().Len() )
     242             :     {
     243           0 :         aFile.Append( pList->GetName() );
     244             : 
     245           0 :         if( aFile.getExtension().isEmpty() )
     246           0 :             aFile.SetExtension( XPropertyList::GetDefaultExt( meType ) );
     247             :     }
     248             : 
     249           0 :     aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
     250           0 :     if ( aDlg.Execute() == ERRCODE_NONE )
     251             :     {
     252           0 :         INetURLObject aURL( aDlg.GetPath() );
     253           0 :         INetURLObject aPathURL( aURL );
     254             : 
     255           0 :         aPathURL.removeSegment();
     256           0 :         aPathURL.removeFinalSlash();
     257             : 
     258           0 :         pList->SetName( aURL.getName() );
     259           0 :         pList->SetPath( aPathURL.GetMainURL( INetURLObject::NO_DECODE ) );
     260             : 
     261           0 :         if( pList->Save() )
     262             :         {
     263           0 :             UpdateTableName();
     264           0 :             AddState( CT_SAVED );
     265           0 :             SetModified( false );
     266             :         }
     267             :         else
     268             :         {
     269             :             ErrorBox aErrorBox( mpTopDlg, WinBits( WB_OK ),
     270           0 :                 String( CUI_RES( RID_SVXSTR_WRITE_DATA_ERROR ) ) );
     271           0 :             aErrorBox.Execute();
     272           0 :         }
     273             :     }
     274           0 :     return 0;
     275             : }
     276             : 
     277           0 : void SvxColorTabPage::Update(bool bLoaded)
     278             : {
     279           0 :     pColorList = XColorListRef( static_cast<XColorList *>( GetList().get() ) );
     280             : 
     281           0 :     if (bLoaded)
     282             :     {
     283           0 :         aLbColor.Clear();
     284           0 :         aValSetColorList.Clear();
     285           0 :         Construct();
     286           0 :         Reset( rOutAttrs );
     287             : 
     288           0 :         if( aLbColor.GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND )
     289           0 :             aLbColor.SelectEntryPos( 0 );
     290             :         else
     291           0 :             aLbColor.SelectEntryPos( aLbColor.GetSelectEntryPos() );
     292             : 
     293           0 :         ChangeColorHdl_Impl( this );
     294           0 :         SelectColorLBHdl_Impl( this );
     295             :     }
     296             : 
     297           0 :     UpdateModified();
     298           0 : }
     299             : 
     300             : // FIXME: you have to hate yourself for this - all this
     301             : // horrible and broadly unused pointer based coupling
     302             : // needs to die. cf SetupForViewFrame
     303             : #define COLORPAGE_UNKNOWN ((sal_uInt16)0xFFFF)
     304             : 
     305             : struct SvxColorTabPageShadow
     306             : {
     307             :     sal_uInt16 nUnknownType;
     308             :     sal_uInt16 nUnknownPos;
     309             :     sal_Bool   bIsAreaTP;
     310             :     sal_uInt16 nChangeType;
     311           0 :     SvxColorTabPageShadow()
     312             :         : nUnknownType( COLORPAGE_UNKNOWN )
     313             :         , nUnknownPos( COLORPAGE_UNKNOWN )
     314             :         , bIsAreaTP( sal_False )
     315           0 :         , nChangeType( 0 )
     316             :     {
     317           0 :     }
     318             : };
     319             : 
     320             : // -----------------------------------------------------------------------
     321             : 
     322           0 : SvxColorTabPage::SvxColorTabPage
     323             : (
     324             :     Window* pParent,
     325             :     const SfxItemSet& rInAttrs
     326             : ) :
     327             : 
     328           0 :     SfxTabPage          ( pParent, CUI_RES( RID_SVXPAGE_COLOR ), rInAttrs ),
     329           0 :     SvxLoadSaveEmbed    ( this, GetParentDialog(),
     330           0 :                           CUI_RES( BTN_LOAD ), CUI_RES( BTN_SAVE ),
     331           0 :                           CUI_RES( BTN_EMBED ), CUI_RES( FT_TABLE_NAME ),
     332           0 :                           XCOLOR_LIST, (XOutdevItemPool*) rInAttrs.GetPool() ),
     333             : 
     334             :     pShadow             ( new SvxColorTabPageShadow() ),
     335           0 :     aFlProp             ( this, CUI_RES( FL_PROP ) ),
     336           0 :     aFtName             ( this, CUI_RES( FT_NAME ) ),
     337           0 :     aEdtName            ( this, CUI_RES( EDT_NAME ) ),
     338           0 :     aFtColor            ( this, CUI_RES( FT_COLOR ) ),
     339           0 :     aLbColor            ( this, CUI_RES( LB_COLOR ) ),
     340             : 
     341           0 :     aValSetColorList   ( this, CUI_RES( CTL_COLORTABLE ) ),
     342             : 
     343           0 :     aCtlPreviewOld      ( this, CUI_RES( CTL_PREVIEW_OLD ) ),
     344           0 :     aCtlPreviewNew      ( this, CUI_RES( CTL_PREVIEW_NEW ) ),
     345             : 
     346           0 :     aLbColorModel       ( this, CUI_RES( LB_COLORMODEL ) ),
     347           0 :     aFtColorModel1      ( this, CUI_RES( FT_1 ) ),
     348           0 :     aMtrFldColorModel1  ( this, CUI_RES( MTR_FLD_1 ) ),
     349           0 :     aFtColorModel2      ( this, CUI_RES( FT_2 ) ),
     350           0 :     aMtrFldColorModel2  ( this, CUI_RES( MTR_FLD_2 ) ),
     351           0 :     aFtColorModel3      ( this, CUI_RES( FT_3 ) ),
     352           0 :     aMtrFldColorModel3  ( this, CUI_RES( MTR_FLD_3 ) ),
     353           0 :     aFtColorModel4      ( this, CUI_RES( FT_4 ) ),
     354           0 :     aMtrFldColorModel4  ( this, CUI_RES( MTR_FLD_4 ) ),
     355           0 :     aBtnAdd             ( this, CUI_RES( BTN_ADD ) ),
     356           0 :     aBtnModify          ( this, CUI_RES( BTN_MODIFY ) ),
     357           0 :     aBtnWorkOn          ( this, CUI_RES( BTN_WORK_ON ) ),
     358           0 :     aBtnDelete          ( this, CUI_RES( BTN_DELETE ) ),
     359             : 
     360             :     rOutAttrs           ( rInAttrs ),
     361             : 
     362             :     // All the horrific pointers we store and should not
     363             :     pPageType           ( NULL ),
     364             :     pDlgType            ( NULL ),
     365             :     pPos                ( NULL ),
     366             :     pbAreaTP            ( NULL ),
     367             : 
     368             :     aXFStyleItem        ( XFILL_SOLID ),
     369             :     aXFillColorItem     ( String(), Color( COL_BLACK ) ),
     370           0 :     aXFillAttr          ( (XOutdevItemPool*) rInAttrs.GetPool() ),
     371           0 :     rXFSet              ( aXFillAttr.GetItemSet() ),
     372           0 :     eCM                 ( CM_RGB )
     373             : {
     374           0 :     FreeResource();
     375             : 
     376             :     // this page needs ExchangeSupport
     377           0 :     SetExchangeSupport();
     378             : 
     379             :     // setting the output device
     380           0 :     rXFSet.Put( aXFStyleItem );
     381           0 :     rXFSet.Put( aXFillColorItem );
     382           0 :     aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
     383           0 :     aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
     384             : 
     385             :     // overload handler
     386             :     aLbColor.SetSelectHdl(
     387           0 :         LINK( this, SvxColorTabPage, SelectColorLBHdl_Impl ) );
     388             :     aValSetColorList.SetSelectHdl(
     389           0 :         LINK( this, SvxColorTabPage, SelectValSetHdl_Impl ) );
     390             :     aLbColorModel.SetSelectHdl(
     391           0 :         LINK( this, SvxColorTabPage, SelectColorModelHdl_Impl ) );
     392             : 
     393           0 :     Link aLink = LINK( this, SvxColorTabPage, ModifiedHdl_Impl );
     394           0 :     aMtrFldColorModel1.SetModifyHdl( aLink );
     395           0 :     aMtrFldColorModel2.SetModifyHdl( aLink );
     396           0 :     aMtrFldColorModel3.SetModifyHdl( aLink );
     397           0 :     aMtrFldColorModel4.SetModifyHdl( aLink );
     398             : 
     399           0 :     aBtnAdd.SetClickHdl( LINK( this, SvxColorTabPage, ClickAddHdl_Impl ) );
     400             :     aBtnModify.SetClickHdl(
     401           0 :         LINK( this, SvxColorTabPage, ClickModifyHdl_Impl ) );
     402             :     aBtnWorkOn.SetClickHdl(
     403           0 :         LINK( this, SvxColorTabPage, ClickWorkOnHdl_Impl ) );
     404             :     aBtnDelete.SetClickHdl(
     405           0 :         LINK( this, SvxColorTabPage, ClickDeleteHdl_Impl ) );
     406             : 
     407             :     // ValueSet
     408           0 :     aValSetColorList.SetStyle( aValSetColorList.GetStyle() | WB_VSCROLL | WB_ITEMBORDER );
     409           0 :     aValSetColorList.SetColCount( 8 );
     410           0 :     aValSetColorList.SetLineCount( 13 );
     411           0 :     aValSetColorList.SetExtraSpacing( 0 );
     412           0 :     aValSetColorList.Show();
     413             : 
     414           0 :     aLbColorModel.SetAccessibleName( String( CUI_RES(STR_CUI_COLORMODEL) ) );
     415           0 :     aBtnAdd.SetAccessibleRelationMemberOf( &aFlProp );
     416           0 :     aBtnModify.SetAccessibleRelationMemberOf( &aFlProp );
     417           0 :     aBtnWorkOn.SetAccessibleRelationMemberOf( &aFlProp );
     418           0 :     aBtnDelete.SetAccessibleRelationMemberOf( &aFlProp );
     419           0 : }
     420             : 
     421           0 : SvxColorTabPage::~SvxColorTabPage()
     422             : {
     423           0 :     delete pShadow;
     424           0 : }
     425             : 
     426             : // -----------------------------------------------------------------------
     427             : 
     428           0 : void SvxColorTabPage::Construct()
     429             : {
     430           0 :     aLbColor.Fill( pColorList );
     431           0 :     FillValueSet_Impl( aValSetColorList );
     432           0 :     UpdateTableName();
     433           0 : }
     434             : 
     435             : // -----------------------------------------------------------------------
     436             : 
     437           0 : void SvxColorTabPage::ActivatePage( const SfxItemSet& )
     438             : {
     439           0 :     if( *pDlgType == 0 ) // area dialog
     440             :     {
     441           0 :         *pbAreaTP = sal_False;
     442             : 
     443           0 :         if( pColorList.is() )
     444             :         {
     445           0 :             if( *pPageType == PT_COLOR && *pPos != LISTBOX_ENTRY_NOTFOUND )
     446             :             {
     447           0 :                 aLbColor.SelectEntryPos( *pPos );
     448           0 :                 aValSetColorList.SelectItem( aLbColor.GetSelectEntryPos() + 1 );
     449           0 :                 aEdtName.SetText( aLbColor.GetSelectEntry() );
     450             : 
     451           0 :                 ChangeColorHdl_Impl( this );
     452             :             }
     453           0 :             else if( *pPageType == PT_COLOR && *pPos == LISTBOX_ENTRY_NOTFOUND )
     454             :             {
     455           0 :                 const SfxPoolItem* pPoolItem = NULL;
     456           0 :                 if( SFX_ITEM_SET == rOutAttrs.GetItemState( GetWhich( XATTR_FILLCOLOR ), sal_True, &pPoolItem ) )
     457             :                 {
     458           0 :                     aLbColorModel.SelectEntryPos( CM_RGB );
     459             : 
     460           0 :                     aAktuellColor.SetColor ( ( ( const XFillColorItem* ) pPoolItem )->GetColorValue().GetColor() );
     461             : 
     462           0 :                     aEdtName.SetText( ( ( const XFillColorItem* ) pPoolItem )->GetName() );
     463             : 
     464           0 :                     aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
     465           0 :                     aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
     466           0 :                     aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
     467             : 
     468             :                     // fill ItemSet and pass it on to XOut
     469           0 :                     rXFSet.Put( XFillColorItem( String(), aAktuellColor ) );
     470           0 :                     aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
     471           0 :                     aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
     472             : 
     473           0 :                     aCtlPreviewNew.Invalidate();
     474           0 :                     aCtlPreviewOld.Invalidate();
     475             :                 }
     476             :             }
     477             : 
     478             :             // so that the possibly changed color is discarded
     479           0 :             SelectColorLBHdl_Impl( this );
     480             : 
     481           0 :             *pPageType = PT_COLOR;
     482           0 :             *pPos = LISTBOX_ENTRY_NOTFOUND;
     483             :         }
     484             :     }
     485             :     else
     486           0 :         HideLoadSaveEmbed();
     487           0 : }
     488             : 
     489             : // -----------------------------------------------------------------------
     490             : 
     491           0 : int SvxColorTabPage::DeactivatePage( SfxItemSet* _pSet )
     492             : {
     493           0 :     if ( CheckChanges_Impl() == -1L )
     494           0 :         return( KEEP_PAGE );
     495             : 
     496           0 :     if( _pSet )
     497           0 :         FillItemSet( *_pSet );
     498             : 
     499           0 :     return( LEAVE_PAGE );
     500             : }
     501             : 
     502             : // -----------------------------------------------------------------------
     503             : 
     504           0 : long SvxColorTabPage::CheckChanges_Impl()
     505             : {
     506             :     // used to NOT lose changes
     507             : 
     508           0 :     Color aTmpColor (aAktuellColor);
     509           0 :     if (eCM != CM_RGB)
     510           0 :         ConvertColorValues (aTmpColor, CM_RGB);
     511             : 
     512           0 :     sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
     513           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     514             :     {
     515           0 :         Color aColor = pColorList->GetColor( nPos )->GetColor();
     516           0 :         String aString = aLbColor.GetSelectEntry();
     517             : 
     518             :         // aNewColor, because COL_USER != COL_something, even if RGB values are the same
     519             :         // Color aNewColor( aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue() );
     520             : 
     521           0 :         if( ColorToPercent_Impl( aTmpColor.GetRed() ) != ColorToPercent_Impl( aColor.GetRed() ) ||
     522           0 :             ColorToPercent_Impl( aTmpColor.GetGreen() ) != ColorToPercent_Impl( aColor.GetGreen() ) ||
     523           0 :             ColorToPercent_Impl( aTmpColor.GetBlue() ) != ColorToPercent_Impl( aColor.GetBlue() ) ||
     524           0 :             aString != aEdtName.GetText() )
     525             :         {
     526           0 :             ResMgr& rMgr = CUI_MGR();
     527           0 :             Image aWarningBoxImage = WarningBox::GetStandardImage();
     528           0 :             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     529           0 :             AbstractSvxMessDialog* aMessDlg = pFact->CreateSvxMessDialog( GetParentDialog(), RID_SVXDLG_MESSBOX,
     530           0 :                                                         SVX_RESSTR( RID_SVXSTR_COLOR ),
     531             :                                                         String( ResId( RID_SVXSTR_ASK_CHANGE_COLOR, rMgr ) ),
     532           0 :                                                         &aWarningBoxImage );
     533             :             aMessDlg->SetButtonText( MESS_BTN_1,
     534           0 :                                     String( ResId( RID_SVXSTR_CHANGE, rMgr ) ) );
     535             :             aMessDlg->SetButtonText( MESS_BTN_2,
     536           0 :                                     String( ResId( RID_SVXSTR_ADD, rMgr ) ) );
     537             : 
     538           0 :             short nRet = aMessDlg->Execute();
     539             : 
     540           0 :             switch( nRet )
     541             :             {
     542             :                 case RET_BTN_1:
     543             :                 {
     544           0 :                     ClickModifyHdl_Impl( this );
     545           0 :                     aColor = pColorList->GetColor( nPos )->GetColor();
     546             :                 }
     547           0 :                 break;
     548             : 
     549             :                 case RET_BTN_2:
     550             :                 {
     551           0 :                     ClickAddHdl_Impl( this );
     552           0 :                     nPos = aLbColor.GetSelectEntryPos();
     553           0 :                     aColor = pColorList->GetColor( nPos )->GetColor();
     554             :                 }
     555           0 :                 break;
     556             : 
     557             :                 case RET_CANCEL:
     558           0 :                 break;
     559             :             }
     560           0 :             delete aMessDlg;
     561           0 :         }
     562             :     }
     563           0 :     if( *pDlgType == 0 ) // area dialog
     564             :     {
     565           0 :         nPos = aLbColor.GetSelectEntryPos();
     566           0 :         if( nPos != LISTBOX_ENTRY_NOTFOUND )
     567             :         {
     568           0 :             *pPos = nPos;
     569             :         }
     570             :     }
     571           0 :     return 0;
     572             : }
     573             : 
     574             : // -----------------------------------------------------------------------
     575             : 
     576           0 : sal_Bool SvxColorTabPage::FillItemSet( SfxItemSet& rSet )
     577             : {
     578           0 :     if( ( *pDlgType != 0 ) ||
     579             :         ( *pPageType == PT_COLOR && *pbAreaTP == sal_False ) )
     580             :     {
     581           0 :         String aString;
     582           0 :         Color  aColor;
     583             : 
     584           0 :         sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
     585           0 :         if( nPos != LISTBOX_ENTRY_NOTFOUND )
     586             :         {
     587           0 :             aColor  = pColorList->GetColor( nPos )->GetColor();
     588           0 :             aString = aLbColor.GetSelectEntry();
     589             :         }
     590             :         else
     591             :         {
     592           0 :             aColor.SetColor (aAktuellColor.GetColor());
     593           0 :             if (eCM != CM_RGB)
     594           0 :                 ConvertColorValues (aColor, CM_RGB);
     595             :         }
     596           0 :         rSet.Put( XFillColorItem( aString, aColor ) );
     597           0 :         rSet.Put( XFillStyleItem( XFILL_SOLID ) );
     598             :     }
     599             : 
     600           0 :     return( sal_True );
     601             : }
     602             : 
     603           0 : void SvxColorTabPage::UpdateModified()
     604             : {
     605           0 :     bool bEnable = pColorList->Count();
     606           0 :     aBtnModify.Enable( bEnable );
     607           0 :     aBtnWorkOn.Enable( bEnable );
     608           0 :     aBtnDelete.Enable( bEnable );
     609           0 :     EnableSave( bEnable );
     610           0 : }
     611             : 
     612             : // -----------------------------------------------------------------------
     613             : 
     614           0 : void SvxColorTabPage::Reset( const SfxItemSet& rSet )
     615             : {
     616           0 :     sal_uInt16 nState = rSet.GetItemState( XATTR_FILLCOLOR );
     617             : 
     618           0 :     if ( nState >= SFX_ITEM_DEFAULT )
     619             :     {
     620           0 :         XFillColorItem aColorItem( (const XFillColorItem&)rSet.Get( XATTR_FILLCOLOR ) );
     621           0 :         aLbColor.SelectEntry( aColorItem.GetColorValue() );
     622           0 :         aValSetColorList.SelectItem( aLbColor.GetSelectEntryPos() + 1 );
     623           0 :         aEdtName.SetText( aLbColor.GetSelectEntry() );
     624             :     }
     625             : 
     626             :     // set color model
     627           0 :     String aStr = GetUserData();
     628           0 :     aLbColorModel.SelectEntryPos( (sal_uInt16) aStr.ToInt32() );
     629             : 
     630           0 :     ChangeColorHdl_Impl( this );
     631           0 :     SelectColorModelHdl_Impl( this );
     632             : 
     633           0 :     aCtlPreviewOld.Invalidate();
     634           0 :     UpdateModified();
     635           0 : }
     636             : 
     637             : // -----------------------------------------------------------------------
     638             : 
     639           0 : SfxTabPage* SvxColorTabPage::Create( Window* pWindow,
     640             :                 const SfxItemSet& rOutAttrs )
     641             : {
     642           0 :     return( new SvxColorTabPage( pWindow, rOutAttrs ) );
     643             : }
     644             : 
     645             : //------------------------------------------------------------------------
     646             : 
     647             : //
     648             : // is called when the content of the MtrFields is changed for color values
     649             : //
     650           0 : IMPL_LINK_NOARG(SvxColorTabPage, ModifiedHdl_Impl)
     651             : {
     652             :     // read current MtrFields, if cmyk, then k-value as transparency
     653           0 :     aAktuellColor.SetColor ( Color( (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel4.GetValue() ),
     654           0 :                                     (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel1.GetValue() ),
     655           0 :                                     (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel2.GetValue() ),
     656           0 :                                     (sal_uInt8)PercentToColor_Impl( (sal_uInt16) aMtrFldColorModel3.GetValue() ) ).GetColor() );
     657             : 
     658           0 :     Color aTmpColor(aAktuellColor);
     659           0 :     if (eCM != CM_RGB)
     660           0 :         ConvertColorValues (aTmpColor, CM_RGB);
     661             : 
     662           0 :     rXFSet.Put( XFillColorItem( String(), aTmpColor ) );
     663           0 :     aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
     664             : 
     665           0 :     aCtlPreviewNew.Invalidate();
     666             : 
     667           0 :     return 0;
     668             : }
     669             : 
     670             : //------------------------------------------------------------------------
     671             : 
     672           0 : IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl)
     673             : {
     674           0 :     Window *pWindow = this;
     675           0 :     while( pWindow )
     676             :     {
     677           0 :         pWindow = pWindow->GetParent();
     678             :     }
     679             : 
     680           0 :     ResMgr& rMgr = CUI_MGR();
     681           0 :     String aDesc( ResId( RID_SVXSTR_DESC_COLOR, rMgr ) );
     682           0 :     String aName( aEdtName.GetText() );
     683             :     XColorEntry* pEntry;
     684           0 :     long nCount = pColorList->Count();
     685           0 :     sal_Bool bDifferent = sal_True;
     686             : 
     687             :     // check if name is already existing
     688           0 :     for ( long i = 0; i < nCount && bDifferent; i++ )
     689           0 :         if ( aName == pColorList->GetColor( i )->GetName() )
     690           0 :             bDifferent = sal_False;
     691             : 
     692             :     // if yes, it is repeated and a new name is demanded
     693           0 :     if ( !bDifferent )
     694             :     {
     695           0 :         WarningBox aWarningBox( GetParentDialog(), WinBits( WB_OK ),
     696           0 :             String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
     697           0 :         aWarningBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
     698           0 :         aWarningBox.Execute();
     699             : 
     700           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     701           0 :         AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
     702           0 :         sal_Bool bLoop = sal_True;
     703             : 
     704           0 :         while ( !bDifferent && bLoop && pDlg->Execute() == RET_OK )
     705             :         {
     706           0 :             pDlg->GetName( aName );
     707           0 :             bDifferent = sal_True;
     708             : 
     709           0 :             for( long i = 0; i < nCount && bDifferent; i++ )
     710             :             {
     711           0 :                 if( aName == pColorList->GetColor( i )->GetName() )
     712           0 :                     bDifferent = sal_False;
     713             :             }
     714             : 
     715           0 :             if( bDifferent )
     716           0 :                 bLoop = sal_False;
     717             :             else
     718           0 :                 aWarningBox.Execute();
     719             :         }
     720           0 :         delete( pDlg );
     721             :     }
     722             : 
     723             :     // if not existing the entry is entered
     724           0 :     if( bDifferent )
     725             :     {
     726           0 :         if (eCM != CM_RGB)
     727           0 :             ConvertColorValues (aAktuellColor, CM_RGB);
     728           0 :         pEntry = new XColorEntry( aAktuellColor, aName );
     729             : 
     730           0 :         pColorList->Insert( pEntry, pColorList->Count() );
     731             : 
     732           0 :         aLbColor.Append( pEntry );
     733           0 :         aValSetColorList.InsertItem( aValSetColorList.GetItemCount() + 1,
     734           0 :                 pEntry->GetColor(), pEntry->GetName() );
     735             : 
     736           0 :         aLbColor.SelectEntryPos( aLbColor.GetEntryCount() - 1 );
     737             : 
     738           0 :         *pnColorListState |= CT_MODIFIED;
     739             : 
     740           0 :         SelectColorLBHdl_Impl( this );
     741             :     }
     742           0 :     UpdateModified();
     743             : 
     744           0 :     return 0;
     745             : }
     746             : 
     747             : //------------------------------------------------------------------------
     748             : 
     749           0 : IMPL_LINK_NOARG(SvxColorTabPage, ClickModifyHdl_Impl)
     750             : {
     751           0 :     sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
     752             : 
     753           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     754             :     {
     755           0 :         ResMgr& rMgr = CUI_MGR();
     756           0 :         String aDesc( ResId( RID_SVXSTR_DESC_COLOR, rMgr ) );
     757           0 :         String aName( aEdtName.GetText() );
     758           0 :         long nCount = pColorList->Count();
     759           0 :         sal_Bool bDifferent = sal_True;
     760             : 
     761             :         // check if name is already existing
     762           0 :         for ( long i = 0; i < nCount && bDifferent; i++ )
     763           0 :             if ( aName == pColorList->GetColor( i )->GetName() && nPos != i )
     764           0 :                 bDifferent = sal_False;
     765             : 
     766             :         // if yes, it is repeated and a new name is demanded
     767           0 :         if ( !bDifferent )
     768             :         {
     769           0 :             WarningBox aWarningBox( GetParentDialog(), WinBits( WB_OK ),
     770           0 :                 String( ResId( RID_SVXSTR_WARN_NAME_DUPLICATE, rMgr ) ) );
     771           0 :             aWarningBox.SetHelpId( HID_WARN_NAME_DUPLICATE );
     772           0 :             aWarningBox.Execute();
     773             : 
     774           0 :             SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     775           0 :             AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc );
     776           0 :             sal_Bool bLoop = sal_True;
     777             : 
     778           0 :             while ( !bDifferent && bLoop && pDlg->Execute() == RET_OK )
     779             :             {
     780           0 :                 pDlg->GetName( aName );
     781           0 :                 bDifferent = sal_True;
     782             : 
     783           0 :                 for ( long i = 0; i < nCount && bDifferent; i++ )
     784           0 :                     if( aName == pColorList->GetColor( i )->GetName() && nPos != i )
     785           0 :                         bDifferent = sal_False;
     786             : 
     787           0 :                 if( bDifferent )
     788           0 :                     bLoop = sal_False;
     789             :                 else
     790           0 :                     aWarningBox.Execute();
     791             :             }
     792           0 :             delete( pDlg );
     793             :         }
     794             : 
     795             :         // if not existing the entry is entered
     796           0 :         if( bDifferent )
     797             :         {
     798           0 :             XColorEntry* pEntry = pColorList->GetColor( nPos );
     799             : 
     800           0 :             Color aTmpColor (aAktuellColor);
     801           0 :             if (eCM != CM_RGB)
     802           0 :                 ConvertColorValues (aTmpColor, CM_RGB);
     803             : 
     804           0 :             pEntry->SetColor( aTmpColor );
     805           0 :             pEntry->SetName( aName );
     806             : 
     807           0 :             aLbColor.Modify( pEntry, nPos );
     808           0 :             aLbColor.SelectEntryPos( nPos );
     809             :             /////
     810           0 :             aValSetColorList.SetItemColor( nPos + 1, pEntry->GetColor() );
     811           0 :             aValSetColorList.SetItemText( nPos + 1, pEntry->GetName() );
     812           0 :             aEdtName.SetText( aName );
     813             : 
     814           0 :             aCtlPreviewOld.Invalidate();
     815             : 
     816           0 :             *pnColorListState |= CT_MODIFIED;
     817           0 :         }
     818             :     }
     819           0 :     return 0;
     820             : }
     821             : 
     822             : //------------------------------------------------------------------------
     823             : 
     824           0 : IMPL_LINK_NOARG(SvxColorTabPage, ClickWorkOnHdl_Impl)
     825             : {
     826           0 :     SvColorDialog* pColorDlg = new SvColorDialog( GetParentDialog() );
     827             : 
     828           0 :     Color aTmpColor (aAktuellColor);
     829           0 :     if (eCM != CM_RGB)
     830           0 :         ConvertColorValues (aTmpColor, CM_RGB);
     831             : 
     832           0 :     pColorDlg->SetColor (aTmpColor);
     833           0 :     pColorDlg->SetMode( svtools::ColorPickerMode_MODIFY );
     834             : 
     835           0 :     if( pColorDlg->Execute() == RET_OK )
     836             :     {
     837           0 :         sal_uInt16 nK = 0;
     838           0 :         Color aPreviewColor = pColorDlg->GetColor();
     839           0 :         aAktuellColor = aPreviewColor;
     840           0 :         if (eCM != CM_RGB)
     841           0 :             ConvertColorValues (aAktuellColor, eCM);
     842             : 
     843           0 :         aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
     844           0 :         aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
     845           0 :         aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
     846           0 :         aMtrFldColorModel4.SetValue( ColorToPercent_Impl( nK ) );
     847             : 
     848             :         // fill ItemSet and pass it on to XOut
     849           0 :         rXFSet.Put( XFillColorItem( String(), aPreviewColor ) );
     850             :         //aCtlPreviewOld.SetAttributes( aXFillAttr );
     851           0 :         aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
     852             : 
     853           0 :         aCtlPreviewNew.Invalidate();
     854             :     }
     855           0 :     delete( pColorDlg );
     856             : 
     857           0 :     return 0;
     858             : }
     859             : 
     860             : //------------------------------------------------------------------------
     861             : 
     862           0 : IMPL_LINK_NOARG(SvxColorTabPage, ClickDeleteHdl_Impl)
     863             : {
     864           0 :     sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
     865             : 
     866           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     867             :     {
     868           0 :         QueryBox aQueryBox( GetParentDialog(), WinBits( WB_YES_NO | WB_DEF_NO ),
     869           0 :             String( CUI_RES( RID_SVXSTR_ASK_DEL_COLOR ) ) );
     870             : 
     871           0 :         if( aQueryBox.Execute() == RET_YES )
     872             :         {
     873           0 :             XColorEntry* pEntry = pColorList->Remove( nPos );
     874             :             DBG_ASSERT( pEntry, "ColorEntry not found !" );
     875           0 :             delete pEntry;
     876             : 
     877             :             // update Listbox and ValueSet
     878           0 :             aLbColor.RemoveEntry( nPos );
     879           0 :             aValSetColorList.Clear();
     880           0 :             FillValueSet_Impl( aValSetColorList );
     881             : 
     882             :             // positioning
     883           0 :             aLbColor.SelectEntryPos( nPos );
     884           0 :             SelectColorLBHdl_Impl( this );
     885             : 
     886           0 :             aCtlPreviewOld.Invalidate();
     887             : 
     888           0 :             *pnColorListState |= CT_MODIFIED;
     889           0 :         }
     890             :     }
     891           0 :     UpdateModified();
     892             : 
     893           0 :     return 0;
     894             : }
     895             : 
     896             : //------------------------------------------------------------------------
     897             : 
     898           0 : IMPL_LINK_NOARG(SvxColorTabPage, SelectColorLBHdl_Impl)
     899             : {
     900           0 :     sal_uInt16 nPos = aLbColor.GetSelectEntryPos();
     901           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     902             :     {
     903           0 :         aValSetColorList.SelectItem( nPos + 1 );
     904           0 :         aEdtName.SetText( aLbColor.GetSelectEntry() );
     905             : 
     906             :         rXFSet.Put( XFillColorItem( String(),
     907           0 :                                     aLbColor.GetSelectEntryColor() ) );
     908           0 :         aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
     909           0 :         aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
     910             : 
     911           0 :         aCtlPreviewOld.Invalidate();
     912           0 :         aCtlPreviewNew.Invalidate();
     913             : 
     914           0 :         ChangeColorHdl_Impl( this );
     915             :     }
     916           0 :     return 0;
     917             : }
     918             : 
     919             : //------------------------------------------------------------------------
     920             : 
     921           0 : IMPL_LINK_NOARG(SvxColorTabPage, SelectValSetHdl_Impl)
     922             : {
     923           0 :     sal_uInt16 nPos = aValSetColorList.GetSelectItemId();
     924           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     925             :     {
     926           0 :         aLbColor.SelectEntryPos( nPos - 1 );
     927           0 :         aEdtName.SetText( aLbColor.GetSelectEntry() );
     928             : 
     929             :         rXFSet.Put( XFillColorItem( String(),
     930           0 :                                     aLbColor.GetSelectEntryColor() ) );
     931           0 :         aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
     932           0 :         aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
     933             : 
     934           0 :         aCtlPreviewOld.Invalidate();
     935           0 :         aCtlPreviewNew.Invalidate();
     936             : 
     937           0 :         ChangeColorHdl_Impl( this );
     938             :     }
     939           0 :     return 0;
     940             : }
     941             : 
     942             : //------------------------------------------------------------------------
     943             : 
     944           0 : void SvxColorTabPage::ConvertColorValues (Color& rColor, ColorModel eModell)
     945             : {
     946           0 :     switch (eModell)
     947             :     {
     948             :         case CM_RGB:
     949             :         {
     950           0 :             CmykToRgb_Impl (rColor, (sal_uInt16)rColor.GetTransparency() );
     951           0 :             rColor.SetTransparency ((sal_uInt8) 0);
     952             :         }
     953           0 :         break;
     954             : 
     955             :         case CM_CMYK:
     956             :         {
     957             :             sal_uInt16 nK;
     958           0 :             RgbToCmyk_Impl (rColor, nK );
     959           0 :             rColor.SetTransparency ((sal_uInt8) nK);
     960             :         }
     961           0 :         break;
     962             :     }
     963           0 : }
     964             : 
     965           0 : IMPL_LINK_NOARG(SvxColorTabPage, SelectColorModelHdl_Impl)
     966             : {
     967           0 :     int nPos = aLbColorModel.GetSelectEntryPos();
     968           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
     969             :     {
     970           0 :         if (eCM != (ColorModel) nPos)
     971             :         {
     972           0 :             ConvertColorValues (aAktuellColor, (ColorModel) nPos);
     973             :         }
     974             : 
     975           0 :         eCM = (ColorModel) nPos;
     976             : 
     977           0 :         switch( eCM )
     978             :         {
     979             :             case CM_RGB:
     980             :             {
     981           0 :                 String aStr( aLbColorModel.GetSelectEntry() );
     982           0 :                 String aColorStr(rtl::OUString("~X"));
     983           0 :                 xub_StrLen nIdx = 1;
     984           0 :                 aColorStr.SetChar( nIdx, aStr.GetChar( 0 ) );
     985           0 :                 aFtColorModel1.SetText( aColorStr );
     986           0 :                 aColorStr.SetChar( nIdx, aStr.GetChar( 1 ) );
     987           0 :                 aFtColorModel2.SetText( aColorStr );
     988           0 :                 aColorStr.SetChar( nIdx, aStr.GetChar( 2 ) );
     989           0 :                 aFtColorModel3.SetText( aColorStr );
     990             : 
     991           0 :                 aFtColorModel4.Hide();
     992           0 :                 aMtrFldColorModel4.Hide();
     993           0 :                 aMtrFldColorModel4.SetValue( 0L );
     994             : 
     995           0 :                 aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_RGB_1 );
     996           0 :                 aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_RGB_2 );
     997           0 :                 aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_RGB_3 );
     998             : 
     999             :                 // Because the old HelpText is still at the Control
    1000             :                 // a change of the HelpID alone would not work
    1001           0 :                 aMtrFldColorModel1.SetHelpText( String() );
    1002           0 :                 aMtrFldColorModel2.SetHelpText( String() );
    1003           0 :                 aMtrFldColorModel3.SetHelpText( String() );
    1004             : 
    1005             :                 // handle RGB-values (0..255, not in %),
    1006             :                 // and adjust MetricFields respectively
    1007           0 :                 aMtrFldColorModel1.SetUnit(FUNIT_NONE);
    1008           0 :                 aMtrFldColorModel1.SetMin(0);
    1009           0 :                 aMtrFldColorModel1.SetMax(255);
    1010           0 :                 aMtrFldColorModel1.SetLast(255);
    1011             : 
    1012           0 :                 aMtrFldColorModel2.SetUnit(FUNIT_NONE);
    1013           0 :                 aMtrFldColorModel2.SetMin(0);
    1014           0 :                 aMtrFldColorModel2.SetMax(255);
    1015           0 :                 aMtrFldColorModel2.SetLast(255);
    1016             : 
    1017           0 :                 aMtrFldColorModel3.SetUnit(FUNIT_NONE);
    1018           0 :                 aMtrFldColorModel3.SetMin(0);
    1019           0 :                 aMtrFldColorModel3.SetMax(255);
    1020           0 :                 aMtrFldColorModel3.SetLast(255);
    1021             :             }
    1022           0 :             break;
    1023             : 
    1024             :             case CM_CMYK:
    1025             :             {
    1026           0 :                 String aStr( aLbColorModel.GetSelectEntry() );
    1027           0 :                 String aColorStr(rtl::OUString("~X"));
    1028           0 :                 xub_StrLen nIdx = 1;
    1029           0 :                 aColorStr.SetChar( nIdx, aStr.GetChar( 0 ) );
    1030           0 :                 aFtColorModel1.SetText( aColorStr );
    1031           0 :                 aColorStr.SetChar( nIdx, aStr.GetChar( 1 ) );
    1032           0 :                 aFtColorModel2.SetText( aColorStr );
    1033           0 :                 aColorStr.SetChar( nIdx,aStr.GetChar( 2 ) );
    1034           0 :                 aFtColorModel3.SetText( aColorStr );
    1035           0 :                 aColorStr.SetChar( nIdx,aStr.GetChar( 3 ) );
    1036           0 :                 aFtColorModel4.SetText( aColorStr );
    1037             : 
    1038           0 :                 aFtColorModel4.Show();
    1039           0 :                 aMtrFldColorModel4.Show();
    1040             : 
    1041           0 :                 aMtrFldColorModel1.SetHelpId( HID_TPCOLOR_CMYK_1 );
    1042           0 :                 aMtrFldColorModel2.SetHelpId( HID_TPCOLOR_CMYK_2 );
    1043           0 :                 aMtrFldColorModel3.SetHelpId( HID_TPCOLOR_CMYK_3 );
    1044             : 
    1045             :                 // s.o.
    1046           0 :                 aMtrFldColorModel1.SetHelpText( String() );
    1047           0 :                 aMtrFldColorModel2.SetHelpText( String() );
    1048           0 :                 aMtrFldColorModel3.SetHelpText( String() );
    1049             : 
    1050             :                 // handle CMYK-values (0..100%)
    1051             :                 // and adjust MetricFields respectively
    1052           0 :                 String aStrUnit( " %" );
    1053             : 
    1054           0 :                 aMtrFldColorModel1.SetUnit(FUNIT_CUSTOM);
    1055           0 :                 aMtrFldColorModel1.SetCustomUnitText( aStrUnit );
    1056           0 :                 aMtrFldColorModel1.SetMin(0);
    1057           0 :                 aMtrFldColorModel1.SetMax(100);
    1058           0 :                 aMtrFldColorModel1.SetLast(100);
    1059             : 
    1060           0 :                 aMtrFldColorModel2.SetUnit(FUNIT_CUSTOM);
    1061           0 :                 aMtrFldColorModel2.SetCustomUnitText( aStrUnit );
    1062           0 :                 aMtrFldColorModel2.SetMin(0);
    1063           0 :                 aMtrFldColorModel2.SetMax(100);
    1064           0 :                 aMtrFldColorModel2.SetLast(100);
    1065             : 
    1066           0 :                 aMtrFldColorModel3.SetUnit(FUNIT_CUSTOM);
    1067           0 :                 aMtrFldColorModel3.SetCustomUnitText( aStrUnit );
    1068           0 :                 aMtrFldColorModel3.SetMin(0);
    1069           0 :                 aMtrFldColorModel3.SetMax(100);
    1070           0 :                 aMtrFldColorModel3.SetLast(100);
    1071             :             }
    1072           0 :             break;
    1073             :         }
    1074             : 
    1075           0 :         aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
    1076           0 :         aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
    1077           0 :         aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
    1078           0 :         aMtrFldColorModel4.SetValue( ColorToPercent_Impl( aAktuellColor.GetTransparency() ) );
    1079             :     }
    1080             : 
    1081           0 :     aMtrFldColorModel1.SetAccessibleName( GetNonMnemonicString(aFtColorModel1.GetText()) );
    1082           0 :     aMtrFldColorModel2.SetAccessibleName( GetNonMnemonicString(aFtColorModel2.GetText()) );
    1083           0 :     aMtrFldColorModel3.SetAccessibleName( GetNonMnemonicString(aFtColorModel3.GetText()) );
    1084           0 :     aMtrFldColorModel4.SetAccessibleName( GetNonMnemonicString(aFtColorModel4.GetText()) );
    1085             : 
    1086           0 :     return 0;
    1087             : }
    1088             : 
    1089             : //------------------------------------------------------------------------
    1090             : 
    1091           0 : long SvxColorTabPage::ChangeColorHdl_Impl( void* )
    1092             : {
    1093           0 :     int nPos = aLbColor.GetSelectEntryPos();
    1094           0 :     if( nPos != LISTBOX_ENTRY_NOTFOUND )
    1095             :     {
    1096           0 :         XColorEntry* pEntry = pColorList->GetColor( nPos );
    1097             : 
    1098           0 :         aAktuellColor.SetColor ( pEntry->GetColor().GetColor() );
    1099           0 :         if (eCM != CM_RGB)
    1100           0 :             ConvertColorValues (aAktuellColor, eCM);
    1101             : 
    1102           0 :         aMtrFldColorModel1.SetValue( ColorToPercent_Impl( aAktuellColor.GetRed() ) );
    1103           0 :         aMtrFldColorModel2.SetValue( ColorToPercent_Impl( aAktuellColor.GetGreen() ) );
    1104           0 :         aMtrFldColorModel3.SetValue( ColorToPercent_Impl( aAktuellColor.GetBlue() ) );
    1105           0 :         aMtrFldColorModel4.SetValue( ColorToPercent_Impl( aAktuellColor.GetTransparency() ) );
    1106             : 
    1107             :         // fill ItemSet and pass it on to XOut
    1108           0 :         rXFSet.Put( XFillColorItem( String(), pEntry->GetColor() ) );
    1109           0 :         aCtlPreviewOld.SetAttributes( aXFillAttr.GetItemSet() );
    1110           0 :         aCtlPreviewNew.SetAttributes( aXFillAttr.GetItemSet() );
    1111             : 
    1112           0 :         aCtlPreviewNew.Invalidate();
    1113             :     }
    1114           0 :     return 0;
    1115             : }
    1116             : 
    1117             : //------------------------------------------------------------------------
    1118             : 
    1119           0 : void SvxColorTabPage::FillValueSet_Impl( ValueSet& rVs )
    1120             : {
    1121           0 :     long nCount = pColorList->Count();
    1122             :     XColorEntry* pColorEntry;
    1123             : 
    1124           0 :     if( nCount > 104 )
    1125           0 :         rVs.SetStyle( rVs.GetStyle() | WB_VSCROLL );
    1126             : 
    1127           0 :     for( long i = 0; i < nCount; i++ )
    1128             :     {
    1129           0 :         pColorEntry = pColorList->GetColor( i );
    1130           0 :         rVs.InsertItem( (sal_uInt16) i + 1, pColorEntry->GetColor(), pColorEntry->GetName() );
    1131             :     }
    1132           0 : }
    1133             : 
    1134             : //------------------------------------------------------------------------
    1135             : 
    1136             : // A RGB value is converted to a CMYK value - not in an ideal way as
    1137             : // R is converted into C, G into M and B into Y. The K value is held in an
    1138             : // extra variable. For further color models one should develop own
    1139             : // classes which should contain the respective casts.
    1140             : 
    1141           0 : void SvxColorTabPage::RgbToCmyk_Impl( Color& rColor, sal_uInt16& rK )
    1142             : {
    1143           0 :     sal_uInt16 const nColor1 = 255 - rColor.GetRed();
    1144           0 :     sal_uInt16 const nColor2 = 255 - rColor.GetGreen();
    1145           0 :     sal_uInt16 const nColor3 = 255 - rColor.GetBlue();
    1146             : 
    1147           0 :     rK = Min( Min( nColor1, nColor2 ), nColor3 );
    1148             : 
    1149           0 :     rColor.SetRed( sal::static_int_cast< sal_uInt8 >( nColor1 - rK ) );
    1150           0 :     rColor.SetGreen( sal::static_int_cast< sal_uInt8 >( nColor2 - rK ) );
    1151           0 :     rColor.SetBlue( sal::static_int_cast< sal_uInt8 >( nColor3 - rK ) );
    1152           0 : }
    1153             : 
    1154             : //------------------------------------------------------------------------
    1155             : 
    1156             : // reverse case to RgbToCmyk_Impl (see above)
    1157             : 
    1158           0 : void SvxColorTabPage::CmykToRgb_Impl( Color& rColor, const sal_uInt16 nK )
    1159             : {
    1160             :     long lTemp;
    1161             : 
    1162           0 :     lTemp = 255 - ( rColor.GetRed() + nK );
    1163             : 
    1164           0 :     if( lTemp < 0L )
    1165           0 :         lTemp = 0L;
    1166           0 :     rColor.SetRed( (sal_uInt8)lTemp );
    1167             : 
    1168           0 :     lTemp = 255 - ( rColor.GetGreen() + nK );
    1169             : 
    1170           0 :     if( lTemp < 0L )
    1171           0 :         lTemp = 0L;
    1172           0 :     rColor.SetGreen( (sal_uInt8)lTemp );
    1173             : 
    1174           0 :     lTemp = 255 - ( rColor.GetBlue() + nK );
    1175             : 
    1176           0 :     if( lTemp < 0L )
    1177           0 :         lTemp = 0L;
    1178           0 :     rColor.SetBlue( (sal_uInt8)lTemp );
    1179           0 : }
    1180             : 
    1181             : //------------------------------------------------------------------------
    1182             : 
    1183           0 : sal_uInt16 SvxColorTabPage::ColorToPercent_Impl( sal_uInt16 nColor )
    1184             : {
    1185           0 :     sal_uInt16 nWert = 0;
    1186             : 
    1187           0 :     switch (eCM)
    1188             :     {
    1189             :         case CM_RGB :
    1190           0 :             nWert = nColor;
    1191           0 :             break;
    1192             : 
    1193             :         case CM_CMYK:
    1194           0 :             nWert = (sal_uInt16) ( (double) nColor * 100.0 / 255.0 + 0.5 );
    1195           0 :             break;
    1196             :     }
    1197             : 
    1198           0 :     return ( nWert );
    1199             : }
    1200             : 
    1201             : //------------------------------------------------------------------------
    1202             : 
    1203           0 : sal_uInt16 SvxColorTabPage::PercentToColor_Impl( sal_uInt16 nPercent )
    1204             : {
    1205           0 :     sal_uInt16 nWert = 0;
    1206             : 
    1207           0 :     switch (eCM)
    1208             :     {
    1209             :         case CM_RGB :
    1210           0 :             nWert = nPercent;
    1211           0 :             break;
    1212             : 
    1213             :         case CM_CMYK:
    1214           0 :             nWert = (sal_uInt16) ( (double) nPercent * 255.0 / 100.0 + 0.5 );
    1215           0 :             break;
    1216             :     }
    1217             : 
    1218           0 :     return ( nWert );
    1219             : }
    1220             : 
    1221             : //------------------------------------------------------------------------
    1222             : 
    1223           0 : void SvxColorTabPage::FillUserData()
    1224             : {
    1225             :     // the color model is saved in the Ini-file
    1226           0 :     SetUserData( OUString::valueOf( static_cast<sal_Int32>(eCM) ) );
    1227           0 : }
    1228             : 
    1229             : //------------------------------------------------------------------------
    1230             : 
    1231           0 : void SvxColorTabPage::SetupForViewFrame( SfxViewFrame *pViewFrame )
    1232             : {
    1233           0 :     const OfaRefItem<XColorList> *pPtr = NULL;
    1234           0 :     if ( pViewFrame != NULL && pViewFrame->GetDispatcher() )
    1235             :         pPtr = (const OfaRefItem<XColorList> *)pViewFrame->
    1236             :             GetDispatcher()->Execute( SID_GET_COLORLIST,
    1237           0 :                                       SFX_CALLMODE_SYNCHRON );
    1238           0 :     pColorList = pPtr ? pPtr->GetValue() : XColorList::GetStdColorList();
    1239             : 
    1240           0 :     SetPageType( &pShadow->nUnknownType );
    1241           0 :     SetDlgType( &pShadow->nUnknownType );
    1242           0 :     SetPos( &pShadow->nUnknownPos );
    1243           0 :     SetAreaTP( &pShadow->bIsAreaTP );
    1244           0 :     SetColorChgd( (ChangeType*)&pShadow->nChangeType );
    1245           0 :     Construct();
    1246           0 : }
    1247             : 
    1248           0 : void SvxColorTabPage::SaveToViewFrame( SfxViewFrame *pViewFrame )
    1249             : {
    1250           0 :     if( !pColorList.is() )
    1251           0 :         return;
    1252             : 
    1253           0 :     pColorList->Save();
    1254             : 
    1255           0 :     if( !pViewFrame )
    1256           0 :         return;
    1257             : 
    1258             :     // notify current viewframe that it uses the same color table
    1259           0 :     if ( !pViewFrame->GetDispatcher() )
    1260           0 :         return;
    1261             : 
    1262             :     const OfaRefItem<XColorList> * pPtr;
    1263           0 :     pPtr = (const OfaRefItem<XColorList>*)pViewFrame->GetDispatcher()->Execute( SID_GET_COLORLIST, SFX_CALLMODE_SYNCHRON );
    1264           0 :     if( pPtr )
    1265             :     {
    1266           0 :         XColorListRef pReference = pPtr->GetValue();
    1267             : 
    1268           0 :         if( pReference.is() &&
    1269           0 :             pReference->GetPath() == pColorList->GetPath() &&
    1270           0 :             pReference->GetName() == pColorList->GetName() )
    1271           0 :             SfxObjectShell::Current()->PutItem( SvxColorListItem( pColorList,
    1272           0 :                                                                   SID_COLOR_TABLE ) );
    1273             :     }
    1274             : }
    1275             : 
    1276           0 : void SvxColorTabPage::SetPropertyList( XPropertyListType t, const XPropertyListRef &xRef )
    1277             : {
    1278             :     (void) t;
    1279             :     OSL_ASSERT( t == XCOLOR_LIST );
    1280           0 :     pColorList = XColorListRef( static_cast<XColorList *>(xRef.get() ) );
    1281           0 : }
    1282             : 
    1283           0 : void SvxColorTabPage::SetColorList( XColorListRef pColList )
    1284             : {
    1285           0 :     SetPropertyList( XCOLOR_LIST, XPropertyListRef( ( pColList.get() ) ) );
    1286           0 : }
    1287             : 
    1288           0 : XPropertyListRef SvxColorTabPage::GetPropertyList( XPropertyListType t )
    1289             : {
    1290             :     (void) t;
    1291             :     OSL_ASSERT( t == XCOLOR_LIST );
    1292           0 :     return XPropertyListRef( pColorList.get() );
    1293           6 : }
    1294             : 
    1295             : 
    1296             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
    1297             : 

Generated by: LCOV version 1.10