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

Generated by: LCOV version 1.10