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

Generated by: LCOV version 1.10