LCOV - code coverage report
Current view: top level - libreoffice/cui/source/dialogs - colorpicker.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 719 0.0 %
Date: 2012-12-17 Functions: 0 77 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 <com/sun/star/uno/XComponentContext.hpp>
      21             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      22             : #include <com/sun/star/beans/XPropertyAccess.hpp>
      23             : #include <com/sun/star/lang/XInitialization.hpp>
      24             : #include <com/sun/star/lang/XServiceInfo.hpp>
      25             : #include <com/sun/star/datatransfer/XTransferable.hpp>
      26             : #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
      27             : #include <com/sun/star/awt/XWindow.hpp>
      28             : #include <cppuhelper/compbase4.hxx>
      29             : #include <comphelper/broadcasthelper.hxx>
      30             : #include <vcl/dialog.hxx>
      31             : #include <vcl/button.hxx>
      32             : #include <vcl/fixed.hxx>
      33             : #include <vcl/edit.hxx>
      34             : #include <vcl/field.hxx>
      35             : #include <vcl/bmpacc.hxx>
      36             : #include <vcl/decoview.hxx>
      37             : #include <vcl/svapp.hxx>
      38             : #include <toolkit/helper/vclunohelper.hxx>
      39             : #include <sot/exchange.hxx>
      40             : #include <sot/formats.hxx>
      41             : #include <sax/tools/converter.hxx>
      42             : #include <basegfx/color/bcolortools.hxx>
      43             : #include "dialmgr.hxx"
      44             : #include "colorpicker.hrc"
      45             : #include <cmath>
      46             : #include <limits>
      47             : 
      48             : using rtl::OUString;
      49             : using namespace ::com::sun::star::uno;
      50             : using namespace ::com::sun::star::lang;
      51             : using namespace ::com::sun::star::ui::dialogs;
      52             : using namespace ::com::sun::star::beans;
      53             : using namespace ::basegfx;
      54             : 
      55             : namespace cui
      56             : {
      57             : const sal_uInt16 COLORMODE_RGB =  0x10;
      58             : const sal_uInt16 COLORMODE_HSV =  0x20;
      59             : const sal_uInt16 COLORMODE_CMYK = 0x40;
      60             : 
      61             : const sal_uInt16 COLORCOMP_RED   = 0x10;
      62             : const sal_uInt16 COLORCOMP_GREEN = 0x11;
      63             : const sal_uInt16 COLORCOMP_BLUE  = 0x12;
      64             : 
      65             : const sal_uInt16 COLORCOMP_HUE  = 0x20;
      66             : const sal_uInt16 COLORCOMP_SAT  = 0x21;
      67             : const sal_uInt16 COLORCOMP_BRI  = 0x22;
      68             : 
      69             : const sal_uInt16 COLORCOMP_CYAN    = 0x40;
      70             : const sal_uInt16 COLORCOMP_YELLOW  = 0x41;
      71             : const sal_uInt16 COLORCOMP_MAGENTA = 0x42;
      72             : const sal_uInt16 COLORCOMP_KEY     = 0x43;
      73             : 
      74             : // color space conversion helpers
      75             : 
      76           0 : static void RGBtoHSV( double dR, double dG, double dB, double& dH, double& dS, double& dV )
      77             : {
      78           0 :     BColor result = tools::rgb2hsv( BColor( dR, dG, dB ) );
      79             : 
      80           0 :     dH = result.getX();
      81           0 :     dS = result.getY();
      82           0 :     dV = result.getZ();
      83           0 : }
      84             : 
      85           0 : static void HSVtoRGB(double dH, double dS, double dV, double& dR, double& dG, double& dB )
      86             : {
      87           0 :     BColor result = tools::hsv2rgb( BColor( dH, dS, dV ) );
      88             : 
      89           0 :     dR = result.getRed();
      90           0 :     dG = result.getGreen();
      91           0 :     dB = result.getBlue();
      92           0 : }
      93             : 
      94             : // -----------------------------------------------------------------------
      95             : 
      96             : // CMYK values from 0 to 1
      97           0 : static void CMYKtoRGB( double fCyan, double fMagenta, double fYellow, double fKey, double& dR, double& dG, double& dB )
      98             : {
      99           0 :     fCyan = (fCyan * ( 1.0 - fKey )) + fKey;
     100           0 :     fMagenta = (fMagenta * ( 1.0 - fKey )) + fKey;
     101           0 :     fYellow = (fYellow * ( 1.0 - fKey )) + fKey;
     102             : 
     103           0 :     dR = std::max( std::min( ( 1.0 - fCyan ), 1.0), 0.0 );
     104           0 :     dG = std::max( std::min( ( 1.0 - fMagenta ), 1.0), 0.0 );
     105           0 :     dB = std::max( std::min( ( 1.0 - fYellow ), 1.0), 0.0 );
     106           0 : }
     107             : 
     108             : // -----------------------------------------------------------------------
     109             : 
     110             : // CMY results from 0 to 1
     111           0 : static void RGBtoCMYK( double dR, double dG, double dB, double& fCyan, double& fMagenta, double& fYellow, double& fKey )
     112             : {
     113           0 :     fCyan = 1 - dR;
     114           0 :     fMagenta = 1 - dG;
     115           0 :     fYellow = 1 - dB;
     116             : 
     117             :     //CMYK and CMY values from 0 to 1
     118           0 :     fKey = 1.0;
     119           0 :     if( fCyan < fKey ) fKey = fCyan;
     120           0 :     if( fMagenta < fKey ) fKey = fMagenta;
     121           0 :     if( fYellow < fKey ) fKey = fYellow;
     122             : 
     123           0 :     if( fKey >= 1.0 )
     124             :     {
     125             :         //Black
     126           0 :        fCyan = 0.0;
     127           0 :        fMagenta = 0.0;
     128           0 :        fYellow = 0.0;
     129             :     }
     130             :     else
     131             :     {
     132           0 :        fCyan = ( fCyan - fKey ) / ( 1.0 - fKey );
     133           0 :        fMagenta = ( fMagenta - fKey ) / ( 1.0 - fKey );
     134           0 :        fYellow = ( fYellow - fKey ) / ( 1.0 - fKey );
     135             :     }
     136           0 : }
     137             : 
     138             : // ====================================================================
     139             : 
     140           0 : class HexColorControl : public Edit
     141             : {
     142             : public:
     143             :     HexColorControl( Window* pParent, const ResId& rResId );
     144             : 
     145             :     virtual long PreNotify( NotifyEvent& rNEvt );
     146             :     virtual void Paste();
     147             : 
     148             :     void SetColor( sal_Int32 nColor );
     149             :     sal_Int32 GetColor();
     150             : 
     151             : private:
     152             :     bool ImplProcessKeyInput( const KeyEvent& rKEv );
     153             : };
     154             : 
     155           0 : HexColorControl::HexColorControl( Window* pParent, const ResId& rResId )
     156           0 : : Edit( pParent, rResId )
     157             : {
     158           0 :     SetMaxTextLen( 6 );
     159           0 : }
     160             : 
     161             : // -----------------------------------------------------------------------
     162             : 
     163           0 : void HexColorControl::SetColor( sal_Int32 nColor )
     164             : {
     165           0 :     ::rtl::OUStringBuffer aBuffer;
     166           0 :     sax::Converter::convertColor( aBuffer, nColor );
     167           0 :     SetText( aBuffer.makeStringAndClear().copy(1) );
     168           0 : }
     169             : 
     170             : // -----------------------------------------------------------------------
     171             : 
     172           0 : sal_Int32 HexColorControl::GetColor()
     173             : {
     174           0 :     sal_Int32 nColor = -1;
     175             : 
     176           0 :     OUString aStr( RTL_CONSTASCII_USTRINGPARAM( "#" ) );
     177           0 :     aStr += GetText();
     178           0 :     sal_Int32 nLen = aStr.getLength();
     179           0 :     if( nLen < 7 )
     180             :     {
     181             :         static const sal_Char* pNullStr = "000000";
     182           0 :         aStr += OUString::createFromAscii( &pNullStr[nLen-1] );
     183             :     }
     184             : 
     185           0 :     sax::Converter::convertColor( nColor, aStr );
     186             : 
     187           0 :     if( nColor == -1 )
     188           0 :         SetControlBackground( Color( COL_RED ) );
     189             :     else
     190           0 :         SetControlBackground();
     191             : 
     192           0 :     return nColor;
     193             : }
     194             : 
     195             : // -----------------------------------------------------------------------
     196             : 
     197           0 : long HexColorControl::PreNotify( NotifyEvent& rNEvt )
     198             : {
     199           0 :     if ( (rNEvt.GetType() == EVENT_KEYINPUT) && !rNEvt.GetKeyEvent()->GetKeyCode().IsMod2() )
     200             :     {
     201           0 :         if ( ImplProcessKeyInput( *rNEvt.GetKeyEvent() ) )
     202           0 :             return 1;
     203             :     }
     204             : 
     205           0 :     return Edit::PreNotify( rNEvt );
     206             : }
     207             : 
     208             : // -----------------------------------------------------------------------
     209             : 
     210           0 : void HexColorControl::Paste()
     211             : {
     212           0 :     ::com::sun::star::uno::Reference<com::sun::star::datatransfer::clipboard::XClipboard> aClipboard(GetClipboard());
     213           0 :     if ( aClipboard.is() )
     214             :     {
     215           0 :         ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > xDataObj;
     216             : 
     217           0 :         const sal_uInt32 nRef = Application::ReleaseSolarMutex();
     218             : 
     219             :         try
     220             :         {
     221           0 :             xDataObj = aClipboard->getContents();
     222             :         }
     223           0 :         catch( const ::com::sun::star::uno::Exception& )
     224             :         {
     225             :         }
     226             : 
     227           0 :         Application::AcquireSolarMutex( nRef );
     228             : 
     229           0 :         if ( xDataObj.is() )
     230             :         {
     231           0 :             ::com::sun::star::datatransfer::DataFlavor aFlavor;
     232           0 :             SotExchange::GetFormatDataFlavor( SOT_FORMAT_STRING, aFlavor );
     233             :             try
     234             :             {
     235           0 :                 ::com::sun::star::uno::Any aData = xDataObj->getTransferData( aFlavor );
     236           0 :                 ::rtl::OUString aText;
     237           0 :                 aData >>= aText;
     238             : 
     239           0 :                 if( !aText.isEmpty() && aText.matchAsciiL( "#", 1, 0 ) )
     240           0 :                     aText = aText.copy(1);
     241             : 
     242           0 :                 if( aText.getLength() > 6 )
     243           0 :                     aText = aText.copy( 0, 6 );
     244             : 
     245           0 :                 SetText( aText );
     246             :             }
     247           0 :             catch( const ::com::sun::star::uno::Exception& )
     248             :             {
     249           0 :             }
     250           0 :         }
     251           0 :     }
     252           0 : }
     253             : 
     254             : // -----------------------------------------------------------------------
     255             : 
     256           0 : bool HexColorControl::ImplProcessKeyInput( const KeyEvent& rKEv )
     257             : {
     258           0 :     const KeyCode& rKeyCode = rKEv.GetKeyCode();
     259             : 
     260           0 :     if( rKeyCode.GetGroup() == KEYGROUP_ALPHA && !rKeyCode.IsMod1() && !rKeyCode.IsMod2() )
     261             :     {
     262           0 :         if( (rKeyCode.GetCode() < KEY_A) || (rKeyCode.GetCode() > KEY_F) )
     263           0 :             return true;
     264             :     }
     265           0 :     else if( rKeyCode.GetGroup() == KEYGROUP_NUM )
     266             :     {
     267           0 :         if( rKeyCode.IsShift() )
     268           0 :             return true;
     269             :     }
     270           0 :     return false;
     271             : }
     272             : 
     273             : // ====================================================================
     274             : 
     275           0 : class ColorPreviewControl : public Control
     276             : {
     277             : public:
     278             :     ColorPreviewControl( Window* pParent, const ResId& rResId );
     279             : 
     280             :     virtual void        Paint( const Rectangle& rRect );
     281             : 
     282             :     void SetColor( const Color& rColor );
     283             : private:
     284             :     Color maColor;
     285             : };
     286             : 
     287             : // -----------------------------------------------------------------------
     288             : 
     289           0 : ColorPreviewControl::ColorPreviewControl( Window* pParent, const ResId& rResId )
     290           0 : : Control( pParent, rResId )
     291             : {
     292           0 :     SetFillColor( maColor );
     293           0 :     SetLineColor( maColor );
     294           0 : }
     295             : 
     296             : // -----------------------------------------------------------------------
     297             : 
     298           0 : void ColorPreviewControl::SetColor( const Color& rCol )
     299             : {
     300           0 :     if( rCol != maColor )
     301             :     {
     302           0 :         maColor = rCol;
     303           0 :         SetFillColor( maColor );
     304           0 :         SetLineColor( maColor );
     305           0 :         Invalidate();
     306             :     }
     307           0 : }
     308             : 
     309             : // -----------------------------------------------------------------------
     310             : 
     311           0 : void ColorPreviewControl::Paint( const Rectangle& rRect )
     312             : {
     313           0 :     DrawRect( rRect );
     314           0 : }
     315             : 
     316             : // ====================================================================
     317             : 
     318             : enum ColorMode { HUE, SATURATION, BRIGHTNESS, RED, GREEN, BLUE };
     319             : const ColorMode DefaultMode = HUE;
     320             : 
     321             : class ColorFieldControl : public Control
     322             : {
     323             : public:
     324             :     ColorFieldControl( Window* pParent, const ResId& rResId );
     325             :     ~ColorFieldControl();
     326             : 
     327             :     virtual void        MouseMove( const MouseEvent& rMEvt );
     328             :     virtual void        MouseButtonDown( const MouseEvent& rMEvt );
     329             :     virtual void        MouseButtonUp( const MouseEvent& rMEvt );
     330             :     virtual void        KeyInput( const KeyEvent& rKEvt );
     331             :     virtual void        Paint( const Rectangle& rRect );
     332             :     virtual void        Resize();
     333             : 
     334             :     void                UpdateBitmap();
     335             :     void                ShowPosition( const Point& rPos, bool bUpdate );
     336             :     void                UpdatePosition();
     337             :     void                Modify();
     338             : 
     339             :     void                SetValues( Color aColor, ColorMode eMode, double x, double y );
     340             :     double              GetX();
     341             :     double              GetY();
     342             : 
     343             :     void                KeyMove( int dx, int dy );
     344             : 
     345           0 :     void                SetModifyHdl( Link& rLink ) { maModifyHdl = rLink; }
     346             : 
     347             : private:
     348             :     Link maModifyHdl;
     349             :     ColorMode meMode;
     350             :     Color maColor;
     351             :     double mdX;
     352             :     double mdY;
     353             :     Point maPosition;
     354             :     Bitmap* mpBitmap;
     355             :     std::vector< sal_uInt8 > maRGB_Horiz;
     356             :     std::vector< sal_uInt16 > maGrad_Horiz;
     357             :     std::vector< sal_uInt16 > maPercent_Horiz;
     358             :     std::vector< sal_uInt8 > maRGB_Vert;
     359             :     std::vector< sal_uInt16 > maPercent_Vert;
     360             : };
     361             : 
     362             : // -----------------------------------------------------------------------
     363             : 
     364           0 : ColorFieldControl::ColorFieldControl( Window* pParent, const ResId& rResId )
     365             : : Control( pParent, rResId )
     366             : , meMode( DefaultMode )
     367             : , mdX( -1.0 )
     368             : , mdY( -1.0 )
     369           0 : , mpBitmap( 0 )
     370             : {
     371           0 :     SetControlBackground();
     372           0 : }
     373             : 
     374             : // -----------------------------------------------------------------------
     375             : 
     376           0 : ColorFieldControl::~ColorFieldControl()
     377             : {
     378           0 :     delete mpBitmap;
     379           0 : }
     380             : 
     381             : // -----------------------------------------------------------------------
     382             : 
     383           0 : void ColorFieldControl::UpdateBitmap()
     384             : {
     385           0 :     const Size aSize( GetOutputSizePixel() );
     386             : 
     387           0 :     if( mpBitmap && mpBitmap->GetSizePixel() != aSize )
     388           0 :         delete mpBitmap, mpBitmap = NULL;
     389             : 
     390           0 :     const sal_Int32 nWidth = aSize.Width();
     391           0 :     const sal_Int32 nHeight = aSize.Height();
     392             : 
     393           0 :     if( !mpBitmap )
     394             :     {
     395           0 :         mpBitmap = new Bitmap( aSize, 24 );
     396             : 
     397           0 :         maRGB_Horiz.resize( nWidth );
     398           0 :         maGrad_Horiz.resize( nWidth );
     399           0 :         maPercent_Horiz.resize( nWidth );
     400             : 
     401           0 :         sal_uInt8* pRGB = &(*maRGB_Horiz.begin());
     402           0 :         sal_uInt16* pGrad = &(*maGrad_Horiz.begin());
     403           0 :         sal_uInt16* pPercent = &(*maPercent_Horiz.begin());
     404             : 
     405           0 :         for( sal_Int32 x = 0; x < nWidth; x++ )
     406             :         {
     407           0 :             *pRGB++ = static_cast< sal_uInt8 >( (x * 256) / nWidth );
     408           0 :             *pGrad++ = static_cast< sal_uInt16 >( (x * 359) / nWidth );
     409           0 :             *pPercent++ = static_cast< sal_uInt16 >( (x * 100) / nWidth );
     410             :         }
     411             : 
     412           0 :         maRGB_Vert.resize( nHeight );
     413           0 :         maPercent_Vert.resize( nHeight );
     414             : 
     415           0 :         pRGB = &(*maRGB_Vert.begin());
     416           0 :         pPercent = &(*maPercent_Vert.begin());
     417             : 
     418           0 :         sal_Int32 y = nHeight;
     419           0 :         while( y-- )
     420             :         {
     421           0 :             *pRGB++ = static_cast< sal_uInt8 >( (y * 256) / nHeight );
     422           0 :             *pPercent++ = static_cast< sal_uInt16 >( (y * 100) / nHeight );
     423             :         }
     424             :     }
     425             : 
     426           0 :     sal_uInt8* pRGB_Horiz = &(*maRGB_Horiz.begin());
     427           0 :     sal_uInt16* pGrad_Horiz = &(*maGrad_Horiz.begin());
     428           0 :     sal_uInt16* pPercent_Horiz = &(*maPercent_Horiz.begin());
     429           0 :     sal_uInt8* pRGB_Vert = &(*maRGB_Vert.begin());
     430           0 :     sal_uInt16* pPercent_Vert = &(*maPercent_Vert.begin());
     431             : 
     432           0 :     BitmapWriteAccess* pWriteAccess = mpBitmap->AcquireWriteAccess();
     433           0 :     if( pWriteAccess )
     434             :     {
     435           0 :         BitmapColor aBitmapColor( maColor );
     436             : 
     437             :         sal_uInt16 nHue, nSat, nBri;
     438           0 :         maColor.RGBtoHSB( nHue, nSat, nBri );
     439             : 
     440             :         // this has been unlooped for performance reason, please do not merge back!
     441             : 
     442           0 :         sal_uInt16 y = nHeight,x;
     443             : 
     444           0 :         switch( meMode )
     445             :         {
     446             :         case HUE:
     447           0 :             while( y-- )
     448             :             {
     449           0 :                 nBri = pPercent_Vert[y];
     450           0 :                 x = nWidth;
     451           0 :                 while( x-- )
     452             :                 {
     453           0 :                     nSat = pPercent_Horiz[x];
     454           0 :                     pWriteAccess->SetPixel( y, x, BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) ) );
     455             :                 }
     456             :             }
     457           0 :             break;
     458             :         case SATURATION:
     459           0 :             while( y-- )
     460             :             {
     461           0 :                 nBri = pPercent_Vert[y];
     462           0 :                 x = nWidth;
     463           0 :                 while( x-- )
     464             :                 {
     465           0 :                     nHue = pGrad_Horiz[x];
     466           0 :                     pWriteAccess->SetPixel( y, x, BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) ) );
     467             :                 }
     468             :             }
     469           0 :             break;
     470             :         case BRIGHTNESS:
     471           0 :             while( y-- )
     472             :             {
     473           0 :                 nSat = pPercent_Vert[y];
     474           0 :                 x = nWidth;
     475           0 :                 while( x-- )
     476             :                 {
     477           0 :                     nHue = pGrad_Horiz[x];
     478           0 :                     pWriteAccess->SetPixel( y, x, BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) ) );
     479             :                 }
     480             :             }
     481           0 :             break;
     482             :         case RED:
     483           0 :             while( y-- )
     484             :             {
     485           0 :                 aBitmapColor.SetGreen( pRGB_Vert[y] );
     486           0 :                 x = nWidth;
     487           0 :                 while( x-- )
     488             :                 {
     489           0 :                     aBitmapColor.SetBlue( pRGB_Horiz[x] );
     490           0 :                     pWriteAccess->SetPixel( y, x, aBitmapColor );
     491             :                 }
     492             :             }
     493           0 :             break;
     494             :         case GREEN:
     495           0 :             while( y-- )
     496             :             {
     497           0 :                 aBitmapColor.SetRed( pRGB_Vert[y] );
     498           0 :                 x = nWidth;
     499           0 :                 while( x-- )
     500             :                 {
     501           0 :                     aBitmapColor.SetBlue( pRGB_Horiz[x] );
     502           0 :                     pWriteAccess->SetPixel( y, x, aBitmapColor );
     503             :                 }
     504             :             }
     505           0 :             break;
     506             :         case BLUE:
     507           0 :             while( y-- )
     508             :             {
     509           0 :                 aBitmapColor.SetGreen( pRGB_Vert[y] );
     510           0 :                 x = nWidth;
     511           0 :                 while( x-- )
     512             :                 {
     513           0 :                     aBitmapColor.SetRed( pRGB_Horiz[x] );
     514           0 :                     pWriteAccess->SetPixel( y, x, aBitmapColor );
     515             :                 }
     516             :             }
     517           0 :             break;
     518             :         }
     519             : 
     520           0 :         mpBitmap->ReleaseAccess( pWriteAccess );
     521             :     }
     522           0 : }
     523             : 
     524             : // -----------------------------------------------------------------------
     525             : 
     526           0 : void ColorFieldControl::ShowPosition( const Point& rPos, bool bUpdate )
     527             : {
     528           0 :     if( !mpBitmap )
     529             :     {
     530           0 :         UpdateBitmap();
     531           0 :         Invalidate();
     532             :     }
     533             : 
     534           0 :     const Size aSize( mpBitmap->GetSizePixel() );
     535             : 
     536           0 :     long nX = rPos.X();
     537           0 :     long nY = rPos.Y();
     538           0 :     if( nX < 0L )
     539           0 :         nX = 0L;
     540           0 :     else if( nX >= aSize.Width() )
     541           0 :         nX = aSize.Width() - 1L;
     542             : 
     543           0 :     if( nY < 0L )
     544           0 :         nY= 0L;
     545           0 :     else if( nY >= aSize.Height() )
     546           0 :         nY = aSize.Height() - 1L;
     547             : 
     548           0 :     Point aPos = maPosition;
     549           0 :     maPosition.X() = nX - 5;
     550           0 :     maPosition.Y() = nY - 5;
     551           0 :     Invalidate( Rectangle( aPos, Size( 11, 11) ) );
     552           0 :     Invalidate( Rectangle( maPosition, Size( 11, 11) ) );
     553             : 
     554           0 :     if( bUpdate )
     555             :     {
     556           0 :         mdX = (double)nX / (double)(aSize.Width()-1);
     557           0 :         mdY = (double)(aSize.Height()-1-nY) / (double)(aSize.Height()-1);
     558             : 
     559           0 :         BitmapReadAccess* pReadAccess = mpBitmap->AcquireReadAccess();
     560           0 :         if( pReadAccess != NULL )
     561             :         {
     562             :             // mpBitmap always has a bit count of 24 => use of GetPixel(...) is safe
     563           0 :             maColor = pReadAccess->GetPixel( nY, nX );
     564           0 :             mpBitmap->ReleaseAccess( pReadAccess );
     565           0 :             pReadAccess = NULL;
     566             :         }
     567             :     }
     568           0 : }
     569             : // -----------------------------------------------------------------------
     570             : 
     571           0 : void ColorFieldControl::MouseMove( const MouseEvent& rMEvt )
     572             : {
     573           0 :     if( rMEvt.IsLeft() )
     574             :     {
     575           0 :         ShowPosition( rMEvt.GetPosPixel(), true );
     576           0 :         Modify();
     577             :     }
     578           0 : }
     579             : 
     580             : // -----------------------------------------------------------------------
     581           0 : void ColorFieldControl::MouseButtonDown( const MouseEvent& rMEvt )
     582             : {
     583           0 :     if( rMEvt.IsLeft() && !rMEvt.IsShift() )
     584             :     {
     585           0 :         CaptureMouse();
     586           0 :         ShowPosition( rMEvt.GetPosPixel(), true );
     587           0 :         Modify();
     588             :     }
     589           0 : }
     590             : 
     591             : // -----------------------------------------------------------------------
     592           0 : void ColorFieldControl::MouseButtonUp( const MouseEvent& )
     593             : {
     594           0 :     if( IsMouseCaptured() )
     595           0 :         ReleaseMouse();
     596           0 : }
     597             : 
     598             : // -----------------------------------------------------------------------
     599             : 
     600           0 : void ColorFieldControl::KeyMove( int dx, int dy )
     601             : {
     602           0 :     Size aSize( GetOutputSizePixel() );
     603           0 :     Point aPos(static_cast<long>(mdX * aSize.Width()), static_cast<long>((1.0 - mdY) * aSize.Height()));
     604           0 :     aPos.X() += dx;
     605           0 :     aPos.Y() += dy;
     606           0 :     if( aPos.X() < 0 )
     607           0 :         aPos.X() += aSize.Width();
     608           0 :     else if( aPos.X() >= aSize.Width() )
     609           0 :         aPos.X() -= aSize.Width();
     610             : 
     611           0 :     if( aPos.Y() < 0 )
     612           0 :         aPos.Y() += aSize.Height();
     613           0 :     else if( aPos.Y() >= aSize.Height() )
     614           0 :         aPos.Y() -= aSize.Height();
     615             : 
     616           0 :     ShowPosition( aPos, true );
     617           0 :     Modify();
     618           0 : }
     619             : 
     620             : // -----------------------------------------------------------------------
     621             : 
     622           0 : void ColorFieldControl::KeyInput( const KeyEvent& rKEvt )
     623             : {
     624           0 :     bool   bShift = rKEvt.GetKeyCode().IsShift();
     625           0 :     bool   bCtrl = rKEvt.GetKeyCode().IsMod1();
     626           0 :     bool   bAlt = rKEvt.GetKeyCode().IsMod2();
     627             : 
     628           0 :     if ( !bAlt && !bShift )
     629             :     {
     630           0 :         switch( rKEvt.GetKeyCode().GetCode() )
     631             :         {
     632           0 :         case KEY_DOWN:      KeyMove(  0, bCtrl ?  5  :  1 ); return;
     633           0 :         case KEY_UP:        KeyMove(  0, bCtrl ? -5  : -1 ); return;
     634           0 :         case KEY_LEFT:      KeyMove( bCtrl ? -5  : -1,  0 ); return;
     635           0 :         case KEY_RIGHT:     KeyMove( bCtrl ?  5  :  1,  0 ); return;
     636             :         }
     637             :     }
     638           0 :     Control::KeyInput( rKEvt );
     639             : }
     640             : 
     641             : // -----------------------------------------------------------------------
     642             : 
     643           0 : void ColorFieldControl::Paint( const Rectangle& rRect )
     644             : {
     645           0 :     if( !mpBitmap )
     646           0 :         UpdateBitmap();
     647             : 
     648           0 :     Bitmap aOutputBitmap( *mpBitmap );
     649             : 
     650           0 :     if( GetBitCount() <= 8 )
     651           0 :         aOutputBitmap.Dither();
     652             : 
     653           0 :     DrawBitmap( rRect.TopLeft(), rRect.GetSize(), rRect.TopLeft(), rRect.GetSize(), aOutputBitmap );
     654             : 
     655             :     // draw circle around current color
     656           0 :     if( maColor.IsDark() )
     657           0 :         SetLineColor( COL_WHITE );
     658             :     else
     659           0 :         SetLineColor( COL_BLACK );
     660             : 
     661           0 :     SetFillColor();
     662             : 
     663           0 :     DrawEllipse( Rectangle( maPosition, Size( 11, 11) ) );
     664           0 : }
     665             : 
     666             : // -----------------------------------------------------------------------
     667             : 
     668           0 : void ColorFieldControl::Resize()
     669             : {
     670           0 :     UpdateBitmap();
     671           0 :     Control::Resize();
     672           0 : }
     673             : 
     674             : // -----------------------------------------------------------------------
     675             : 
     676           0 : void ColorFieldControl::Modify()
     677             : {
     678           0 :     maModifyHdl.Call( this );
     679           0 : }
     680             : 
     681             : // -----------------------------------------------------------------------
     682             : 
     683           0 : void ColorFieldControl::SetValues( Color aColor, ColorMode eMode, double x, double y )
     684             : {
     685           0 :     bool bUpdateBitmap = (maColor!= aColor) || (meMode != eMode);
     686           0 :     if( bUpdateBitmap || (mdX != x) || (mdY != y) )
     687             :     {
     688           0 :         maColor = aColor;
     689           0 :         meMode = eMode;
     690           0 :         mdX = x;
     691           0 :         mdY = y;
     692             : 
     693           0 :         if( bUpdateBitmap )
     694           0 :             UpdateBitmap();
     695           0 :         UpdatePosition();
     696           0 :         if( bUpdateBitmap )
     697           0 :             Invalidate();
     698             :     }
     699           0 : }
     700             : 
     701             : // -----------------------------------------------------------------------
     702             : 
     703           0 : double ColorFieldControl::GetX()
     704             : {
     705           0 :     return mdX;
     706             : }
     707             : 
     708             : // -----------------------------------------------------------------------
     709             : 
     710           0 : double ColorFieldControl::GetY()
     711             : {
     712           0 :     return mdY;
     713             : }
     714             : 
     715             : // -----------------------------------------------------------------------
     716             : 
     717           0 : void ColorFieldControl::UpdatePosition()
     718             : {
     719           0 :     Size aSize( GetOutputSizePixel() );
     720           0 :     ShowPosition( Point(static_cast<long>(mdX * aSize.Width()), static_cast<long>((1.0 - mdY) * aSize.Height())), false );
     721           0 : }
     722             : 
     723             : // ====================================================================
     724             : 
     725             : class ColorSliderControl : public Control
     726             : {
     727             : public:
     728             :     ColorSliderControl( Window* pParent, const ResId& rResId );
     729             :     ~ColorSliderControl();
     730             : 
     731             :     virtual void        MouseMove( const MouseEvent& rMEvt );
     732             :     virtual void        MouseButtonDown( const MouseEvent& rMEvt );
     733             :     virtual void        MouseButtonUp( const MouseEvent& rMEvt );
     734             :     virtual void        KeyInput( const KeyEvent& rKEvt );
     735             :     virtual void        Paint( const Rectangle& rRect );
     736             :     virtual void        Resize();
     737             : 
     738             :     void                UpdateBitmap();
     739             :     void                ChangePosition( long nY );
     740             :     void                Modify();
     741             : 
     742             :     void SetValue( const Color& rColor, ColorMode eMode, double dValue );
     743           0 :     double GetValue() const { return mdValue; }
     744             : 
     745             :     void                KeyMove( int dy );
     746             : 
     747           0 :     void SetModifyHdl( Link& rLink ) { maModifyHdl = rLink; }
     748             : 
     749           0 :     sal_Int16 GetLevel() const { return mnLevel; }
     750             : 
     751             : private:
     752             :     Link maModifyHdl;
     753             :     Color maColor;
     754             :     ColorMode meMode;
     755             :     Bitmap* mpBitmap;
     756             :     sal_Int16 mnLevel;
     757             :     double mdValue;
     758             : };
     759             : 
     760             : // -----------------------------------------------------------------------
     761             : 
     762           0 : ColorSliderControl::ColorSliderControl( Window* pParent, const ResId& rResId )
     763             : : Control( pParent, rResId )
     764             : , meMode( DefaultMode )
     765             : , mpBitmap( 0 )
     766             : , mnLevel( 0 )
     767           0 : , mdValue( -1.0 )
     768             : {
     769           0 :     SetControlBackground();
     770           0 : }
     771             : 
     772             : // -----------------------------------------------------------------------
     773             : 
     774           0 : ColorSliderControl::~ColorSliderControl()
     775             : {
     776           0 :     delete mpBitmap;
     777           0 : }
     778             : 
     779             : // -----------------------------------------------------------------------
     780             : 
     781           0 : void ColorSliderControl::UpdateBitmap()
     782             : {
     783           0 :     Size aSize( 1, GetOutputSizePixel().Height() );
     784             : 
     785           0 :     if( mpBitmap && mpBitmap->GetSizePixel() != aSize )
     786           0 :         delete mpBitmap, mpBitmap = NULL;
     787             : 
     788           0 :     if( !mpBitmap )
     789           0 :         mpBitmap = new Bitmap( aSize, 24 );
     790             : 
     791           0 :     BitmapWriteAccess* pWriteAccess = mpBitmap->AcquireWriteAccess();
     792             : 
     793           0 :     if( pWriteAccess )
     794             :     {
     795           0 :         const long nY = aSize.Height()-1;
     796             : 
     797           0 :         BitmapColor aBitmapColor( maColor );
     798             : 
     799             :         sal_uInt16 nHue, nSat, nBri;
     800           0 :         maColor.RGBtoHSB( nHue, nSat, nBri );
     801             : 
     802             :         // this has been unlooped for performance reason, please do not merge back!
     803             : 
     804           0 :         switch( meMode )
     805             :         {
     806             :         case HUE:
     807           0 :             nSat = 100;
     808           0 :             nBri = 100;
     809           0 :             for( long y = 0; y <= nY; y++ )
     810             :             {
     811           0 :                 nHue = static_cast< sal_uInt16 >( (359 * y) / nY );
     812           0 :                 aBitmapColor = BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) );
     813           0 :                 pWriteAccess->SetPixel( nY-y, 0, aBitmapColor );
     814             :             }
     815           0 :             break;
     816             : 
     817             :         case SATURATION:
     818           0 :             nBri = std::max( (sal_uInt16)32, nBri );
     819           0 :             for( long y = 0; y <= nY; y++ )
     820             :             {
     821           0 :                 nSat = static_cast< sal_uInt16 >( (100 * y) / nY );
     822           0 :                 pWriteAccess->SetPixel( nY-y, 0, BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) ) );
     823             :             }
     824           0 :             break;
     825             : 
     826             :         case BRIGHTNESS:
     827           0 :             for( long y = 0; y <= nY; y++ )
     828             :             {
     829           0 :                 nBri = static_cast< sal_uInt16 >( (100 * y) / nY );
     830           0 :                 pWriteAccess->SetPixel( nY-y, 0, BitmapColor( Color( Color::HSBtoRGB( nHue, nSat, nBri ) ) ) );
     831             :             }
     832           0 :             break;
     833             : 
     834             :         case RED:
     835           0 :             for( long y = 0; y <= nY; y++ )
     836             :             {
     837           0 :                 aBitmapColor.SetRed( sal_uInt8( ((long)255 * y) / nY ) );
     838           0 :                 pWriteAccess->SetPixel( nY-y, 0, aBitmapColor );
     839             :             }
     840           0 :             break;
     841             : 
     842             :         case GREEN:
     843           0 :             for( long y = 0; y <= nY; y++ )
     844             :             {
     845           0 :                 aBitmapColor.SetGreen( sal_uInt8( ((long)255 * y) / nY ) );
     846           0 :                 pWriteAccess->SetPixel( nY-y, 0, aBitmapColor );
     847             :             }
     848           0 :             break;
     849             : 
     850             :         case BLUE:
     851           0 :             for( long y = 0; y <= nY; y++ )
     852             :             {
     853           0 :                 aBitmapColor.SetBlue( sal_uInt8( ((long)255 * y) / nY ) );
     854           0 :                 pWriteAccess->SetPixel( nY-y, 0, aBitmapColor );
     855             :             }
     856           0 :             break;
     857             :         }
     858             : 
     859           0 :         mpBitmap->ReleaseAccess( pWriteAccess );
     860             :     }
     861           0 : }
     862             : 
     863             : // -----------------------------------------------------------------------
     864             : 
     865           0 : void ColorSliderControl::ChangePosition( long nY )
     866             : {
     867           0 :     const long nHeight = GetOutputSizePixel().Height() - 1;
     868             : 
     869           0 :     if( nY < 0L )
     870           0 :         nY = 0;
     871           0 :     else if( nY > nHeight )
     872           0 :         nY = nHeight;
     873             : 
     874           0 :     mnLevel = nY;
     875           0 :     mdValue = ((double)(nHeight - nY)) / (double)nHeight;
     876           0 : }
     877             : 
     878             : // -----------------------------------------------------------------------
     879             : 
     880           0 : void ColorSliderControl::MouseMove( const MouseEvent& rMEvt )
     881             : {
     882           0 :     if( rMEvt.IsLeft() )
     883             :     {
     884           0 :         ChangePosition( rMEvt.GetPosPixel().Y() );
     885           0 :         Modify();
     886             :     }
     887           0 : }
     888             : 
     889             : // -----------------------------------------------------------------------
     890           0 : void ColorSliderControl::MouseButtonDown( const MouseEvent& rMEvt )
     891             : {
     892           0 :     if( rMEvt.IsLeft() && !rMEvt.IsShift() )
     893             :     {
     894           0 :         CaptureMouse();
     895           0 :         ChangePosition( rMEvt.GetPosPixel().Y() );
     896           0 :         Modify();
     897             :     }
     898           0 : }
     899             : 
     900             : // -----------------------------------------------------------------------
     901           0 : void ColorSliderControl::MouseButtonUp( const MouseEvent& )
     902             : {
     903           0 :     if( IsMouseCaptured() )
     904           0 :         ReleaseMouse();
     905           0 : }
     906             : 
     907             : // -----------------------------------------------------------------------
     908             : 
     909           0 : void ColorSliderControl::KeyMove( int dy )
     910             : {
     911           0 :     ChangePosition( mnLevel + dy );
     912           0 :     Modify();
     913           0 : }
     914             : 
     915             : // -----------------------------------------------------------------------
     916             : 
     917           0 : void ColorSliderControl::KeyInput( const KeyEvent& rKEvt )
     918             : {
     919           0 :     if ( !rKEvt.GetKeyCode().IsMod2() && !rKEvt.GetKeyCode().IsShift() )
     920             :     {
     921           0 :         switch( rKEvt.GetKeyCode().GetCode() )
     922             :         {
     923           0 :         case KEY_DOWN:      KeyMove(  rKEvt.GetKeyCode().IsMod1() ?  5 :  1 ); return;
     924           0 :         case KEY_UP:        KeyMove(  rKEvt.GetKeyCode().IsMod1() ? -5 : -1 ); return;
     925             :         }
     926             :     }
     927             : 
     928           0 :     Control::KeyInput( rKEvt );
     929             : }
     930             : // -----------------------------------------------------------------------
     931             : 
     932           0 : void ColorSliderControl::Paint( const Rectangle& /*rRect*/ )
     933             : {
     934           0 :     if( !mpBitmap )
     935           0 :         UpdateBitmap();
     936             : 
     937           0 :     const Size aSize( GetOutputSizePixel() );
     938             : 
     939           0 :     Bitmap aOutputBitmap( *mpBitmap );
     940             : 
     941           0 :     if( GetBitCount() <= 8 )
     942           0 :         aOutputBitmap.Dither();
     943             : 
     944           0 :     Point aPos;
     945           0 :     int x = aSize.Width();
     946           0 :     while( x-- )
     947             :     {
     948           0 :         DrawBitmap( aPos, aOutputBitmap );
     949           0 :         aPos.X() += 1;
     950           0 :     }
     951           0 : }
     952             : 
     953             : // -----------------------------------------------------------------------
     954             : 
     955           0 : void ColorSliderControl::Resize()
     956             : {
     957           0 :     UpdateBitmap();
     958           0 :     Control::Resize();
     959           0 : }
     960             : 
     961             : // -----------------------------------------------------------------------
     962             : 
     963           0 : void ColorSliderControl::Modify()
     964             : {
     965           0 :     maModifyHdl.Call( this );
     966           0 : }
     967             : 
     968             : // -----------------------------------------------------------------------
     969             : 
     970           0 : void ColorSliderControl::SetValue( const Color& rColor, ColorMode eMode, double dValue )
     971             : {
     972           0 :     bool bUpdateBitmap = (rColor != maColor) || (eMode != meMode);
     973           0 :     if( bUpdateBitmap || (mdValue != dValue))
     974             :     {
     975           0 :         maColor = rColor;
     976           0 :         mdValue = dValue;
     977           0 :         mnLevel = static_cast<sal_Int16>((1.0-dValue) * GetOutputSizePixel().Height());
     978           0 :         meMode = eMode;
     979           0 :         if( bUpdateBitmap )
     980           0 :             UpdateBitmap();
     981           0 :         Invalidate();
     982             :     }
     983           0 : }
     984             : 
     985             : // ====================================================================
     986             : 
     987             : const sal_uInt16 UPDATE_RGB = 0x01;
     988             : const sal_uInt16 UPDATE_CMYK = 0x02;
     989             : const sal_uInt16 UPDATE_HSB = 0x04;
     990             : const sal_uInt16 UPDATE_COLORCHOOSER = 0x08;
     991             : const sal_uInt16 UPDATE_COLORSLIDER = 0x10;
     992             : const sal_uInt16 UPDATE_HEX = 0x20;
     993             : const sal_uInt16 UPDATE_ALL = 0xff;
     994             : 
     995           0 : class ColorPickerDialog : public ModalDialog
     996             : {
     997             : public:
     998             :     ColorPickerDialog( Window* pParent, sal_Int32 nColor, sal_Int16 nMode );
     999             : 
    1000             :     void update_color( sal_uInt16 n = UPDATE_ALL );
    1001             : 
    1002             :     DECL_LINK( ColorModifyHdl, void * );
    1003             :     DECL_LINK( ModeModifyHdl, void * );
    1004             : 
    1005             :     sal_Int32 GetColor() const;
    1006             : 
    1007             :     void setColorComponent( sal_uInt16 nComp, double dValue );
    1008             : 
    1009             : private:
    1010             :     Color maPreviousColor;
    1011             :     sal_Int16 mnDialogMode;
    1012             :     ColorMode meMode;
    1013             : 
    1014             :     double mdRed, mdGreen, mdBlue;
    1015             :     double mdHue, mdSat, mdBri;
    1016             :     double mdCyan, mdMagenta, mdYellow, mdKey;
    1017             : 
    1018             : private:
    1019             :     ColorFieldControl  maColorField;
    1020             :     ColorSliderControl maColorSlider;
    1021             :     ColorPreviewControl maColorPreview;
    1022             :     ColorPreviewControl maColorPrevious;
    1023             : 
    1024             :     FixedImage maFISliderLeft;
    1025             :     FixedImage maFISliderRight;
    1026             :     Image maSliderImage;
    1027             : 
    1028             : #if 0
    1029             :     ImageButton maBtnPicker;
    1030             : #endif
    1031             : 
    1032             :     FixedLine maFLRGB;
    1033             : 
    1034             :     RadioButton maRBRed;
    1035             :     RadioButton maRBGreen;
    1036             :     RadioButton maRBBlue;
    1037             :     RadioButton maRBHue;
    1038             :     RadioButton maRBSaturation;
    1039             :     RadioButton maRBBrightness;
    1040             : 
    1041             :     FixedText maFTRed;
    1042             :     MetricField maMFRed;
    1043             :     FixedText maFTGreen;
    1044             :     MetricField maMFGreen;
    1045             :     FixedText maFTBlue;
    1046             :     MetricField maMFBlue;
    1047             :     FixedText maFTHex;
    1048             :     HexColorControl maEDHex;
    1049             : 
    1050             :     FixedLine maFLHSB;
    1051             :     FixedText maFTHue;
    1052             :     MetricField maMFHue;
    1053             :     FixedText maFTSaturation;
    1054             :     MetricField maMFSaturation;
    1055             :     FixedText maFTBrightness;
    1056             :     MetricField maMFBrightness;
    1057             : 
    1058             :     FixedLine maFLCMYK;
    1059             :     FixedText maFTCyan;
    1060             :     MetricField maMFCyan;
    1061             :     FixedText maFTMagenta;
    1062             :     MetricField maMFMagenta;
    1063             :     FixedText maFTYellow;
    1064             :     MetricField maMFYellow;
    1065             :     FixedText maFTKey;
    1066             :     MetricField maMFKey;
    1067             : 
    1068             :     FixedLine maFLBottmLine;
    1069             :     HelpButton maBTNHelp;
    1070             :     OKButton maBTNOk;
    1071             :     CancelButton maBTNCancel;
    1072             : };
    1073             : 
    1074             : // --------------------------------------------------------------------
    1075             : 
    1076           0 : ColorPickerDialog::ColorPickerDialog( Window* pParent, sal_Int32 nColor, sal_Int16 nMode )
    1077           0 : : ModalDialog( pParent, CUI_RES( RID_CUI_DIALOG_COLORPICKER ) )
    1078             : , maPreviousColor( nColor )
    1079             : , mnDialogMode( nMode )
    1080             : , meMode( DefaultMode )
    1081           0 : , maColorField( this, CUI_RES( CT_COLORFIELD ) )
    1082           0 : , maColorSlider( this, CUI_RES( CT_COLORSLIDER ) )
    1083           0 : , maColorPreview( this, CUI_RES( CT_PREVIEW ) )
    1084           0 : , maColorPrevious( this, CUI_RES( CT_PREVIOUS ) )
    1085           0 : , maFISliderLeft(  this, CUI_RES( CT_LEFT_SLIDER ) )
    1086           0 : , maFISliderRight( this, CUI_RES( CT_RIGHT_SLIDER ) )
    1087           0 : , maSliderImage( CUI_RES( CT_SLIDERIMG ) )
    1088             : #if 0
    1089             : , maBtnPicker( this, CUI_RES( PB_PICKER ) )
    1090             : #endif
    1091           0 : , maFLRGB( this, CUI_RES( FL_RGB ) )
    1092           0 : , maRBRed( this, CUI_RES( CT_RED ) )
    1093           0 : , maRBGreen( this, CUI_RES( CT_GREEN ) )
    1094           0 : , maRBBlue( this, CUI_RES( CT_BLUE ) )
    1095           0 : , maRBHue( this, CUI_RES( CT_HUE ) )
    1096           0 : , maRBSaturation( this, CUI_RES( CT_SATURATION ) )
    1097           0 : , maRBBrightness( this, CUI_RES( CT_BRIGHTNESS ) )
    1098           0 : , maFTRed( this, CUI_RES( CT_RED ) )
    1099           0 : , maMFRed( this, CUI_RES( CT_RED ) )
    1100           0 : , maFTGreen( this, CUI_RES( CT_GREEN ) )
    1101           0 : , maMFGreen( this, CUI_RES( CT_GREEN ) )
    1102           0 : , maFTBlue( this, CUI_RES( CT_BLUE ) )
    1103           0 : , maMFBlue( this, CUI_RES( CT_BLUE ) )
    1104           0 : , maFTHex( this, CUI_RES( CT_HEX ) )
    1105           0 : , maEDHex( this, CUI_RES( CT_HEX ) )
    1106           0 : , maFLHSB( this, CUI_RES( FL_HSB ) )
    1107           0 : , maFTHue( this, CUI_RES( CT_HUE ) )
    1108           0 : , maMFHue( this, CUI_RES( CT_HUE ) )
    1109           0 : , maFTSaturation( this, CUI_RES( CT_SATURATION ) )
    1110           0 : , maMFSaturation( this, CUI_RES( CT_SATURATION ) )
    1111           0 : , maFTBrightness( this, CUI_RES( CT_BRIGHTNESS ) )
    1112           0 : , maMFBrightness( this, CUI_RES( CT_BRIGHTNESS ) )
    1113           0 : , maFLCMYK( this, CUI_RES( FL_CMYK ) )
    1114           0 : , maFTCyan( this, CUI_RES( CT_CYAN ) )
    1115           0 : , maMFCyan( this, CUI_RES( CT_CYAN ) )
    1116           0 : , maFTMagenta( this, CUI_RES( CT_MAGENTA ) )
    1117           0 : , maMFMagenta( this, CUI_RES( CT_MAGENTA ) )
    1118           0 : , maFTYellow( this, CUI_RES( CT_YELLOW ) )
    1119           0 : , maMFYellow( this, CUI_RES( CT_YELLOW ) )
    1120           0 : , maFTKey( this, CUI_RES( CT_KEY ) )
    1121           0 : , maMFKey( this, CUI_RES( CT_KEY ) )
    1122             : 
    1123           0 : , maFLBottmLine( this, CUI_RES( FT_BOTTOMLINE ) )
    1124           0 : , maBTNHelp( this, CUI_RES( BTN_HELP ) )
    1125           0 : , maBTNOk( this, CUI_RES( BTN_OK ) )
    1126           0 : , maBTNCancel( this, CUI_RES( BTN_CANCEL ) )
    1127             : {
    1128           0 :     FreeResource();
    1129             : 
    1130           0 :     Link aLink( LINK( this, ColorPickerDialog, ColorModifyHdl ) );
    1131           0 :     maColorField.SetModifyHdl( aLink );
    1132           0 :     maColorSlider.SetModifyHdl( aLink );
    1133             : 
    1134           0 :     maMFRed.SetModifyHdl( aLink );
    1135           0 :     maMFGreen.SetModifyHdl( aLink );
    1136           0 :     maMFBlue.SetModifyHdl( aLink );
    1137             : 
    1138           0 :     maMFCyan.SetModifyHdl( aLink );
    1139           0 :     maMFMagenta.SetModifyHdl( aLink );
    1140           0 :     maMFYellow.SetModifyHdl( aLink );
    1141           0 :     maMFKey.SetModifyHdl( aLink );
    1142             : 
    1143           0 :     maMFHue.SetModifyHdl( aLink );
    1144           0 :     maMFSaturation.SetModifyHdl( aLink );
    1145           0 :     maMFBrightness.SetModifyHdl( aLink );
    1146             : 
    1147           0 :     maEDHex.SetModifyHdl( aLink );
    1148             : 
    1149           0 :     aLink = LINK( this, ColorPickerDialog, ModeModifyHdl );
    1150           0 :     maRBRed.SetToggleHdl( aLink );
    1151           0 :     maRBGreen.SetToggleHdl( aLink );
    1152           0 :     maRBBlue.SetToggleHdl( aLink );
    1153           0 :     maRBHue.SetToggleHdl( aLink );
    1154           0 :     maRBSaturation.SetToggleHdl( aLink );
    1155           0 :     maRBBrightness.SetToggleHdl( aLink );
    1156             : 
    1157           0 :     Image aSliderImage( maSliderImage );
    1158             : 
    1159           0 :     maFISliderLeft.SetImage( aSliderImage );
    1160             : 
    1161           0 :     BitmapEx aTmpBmp( maSliderImage.GetBitmapEx() );
    1162           0 :     aTmpBmp.Mirror( BMP_MIRROR_HORZ );
    1163           0 :     maFISliderRight.SetImage( Image( aTmpBmp  ) );
    1164             : 
    1165           0 :     Size aSize( maSliderImage.GetSizePixel() );
    1166           0 :     maFISliderLeft.SetSizePixel( aSize );
    1167           0 :     maFISliderRight.SetSizePixel( aSize );
    1168             : 
    1169           0 :     Point aPos( maColorSlider.GetPosPixel() );
    1170             : 
    1171           0 :     aPos.X() -= aSize.Width();
    1172           0 :     aPos.Y() -= aSize.Height() / 2;
    1173           0 :     maFISliderLeft.SetPosPixel( aPos );
    1174             : 
    1175           0 :     aPos.X() += aSize.Width() + maColorSlider.GetSizePixel().Width();
    1176           0 :     maFISliderRight.SetPosPixel( aPos );
    1177             : 
    1178           0 :     Color aColor( nColor );
    1179             : 
    1180             :     // modify
    1181           0 :     if( mnDialogMode == 2 )
    1182             :     {
    1183           0 :         maColorPreview.SetSizePixel( maColorPrevious.GetSizePixel() );
    1184           0 :         maColorPrevious.SetColor( aColor );
    1185           0 :         maColorPrevious.Show( true );
    1186             :     }
    1187             : 
    1188           0 :     mdRed = ((double)aColor.GetRed()) / 255.0;
    1189           0 :     mdGreen = ((double)aColor.GetGreen()) / 255.0;
    1190           0 :     mdBlue = ((double)aColor.GetBlue()) / 255.0;
    1191             : 
    1192           0 :     RGBtoHSV( mdRed, mdGreen, mdBlue, mdHue, mdSat, mdBri );
    1193           0 :     RGBtoCMYK( mdRed, mdGreen, mdBlue, mdCyan, mdMagenta, mdYellow, mdKey );
    1194             : 
    1195           0 :     update_color();
    1196           0 : }
    1197             : 
    1198             : // --------------------------------------------------------------------
    1199             : 
    1200           0 : static int toInt( double dValue, double dRange )
    1201             : {
    1202           0 :     return static_cast< int >( std::floor((dValue * dRange) + 0.5 ) );
    1203             : }
    1204             : 
    1205           0 : sal_Int32 ColorPickerDialog::GetColor() const
    1206             : {
    1207           0 :     return Color( toInt(mdRed,255.0), toInt(mdGreen,255.0), toInt(mdBlue,255.0) ).GetColor();
    1208             : }
    1209             : 
    1210           0 : void ColorPickerDialog::update_color( sal_uInt16 n )
    1211             : {
    1212           0 :     sal_uInt8 nRed = toInt(mdRed,255.0);
    1213           0 :     sal_uInt8 nGreen = toInt(mdGreen,255.0);
    1214           0 :     sal_uInt8 nBlue = toInt(mdBlue,255.0);
    1215             : 
    1216           0 :     Color aColor( nRed, nGreen, nBlue );
    1217             : 
    1218           0 :     if( n & UPDATE_RGB ) // update RGB
    1219             :     {
    1220           0 :         maMFRed.SetValue( nRed );
    1221           0 :         maMFGreen.SetValue( nGreen );
    1222           0 :         maMFBlue.SetValue( nBlue );
    1223             :     }
    1224             : 
    1225           0 :     if( n & UPDATE_CMYK ) // update CMYK
    1226             :     {
    1227           0 :         maMFCyan.SetValue( toInt( mdCyan, 100.0 ) );
    1228           0 :         maMFMagenta.SetValue( toInt( mdMagenta, 100.0 ) );
    1229           0 :         maMFYellow.SetValue( toInt( mdYellow, 100.0 ) );
    1230           0 :         maMFKey.SetValue( toInt( mdKey, 100.0 ) );
    1231             :     }
    1232             : 
    1233           0 :     if( n & UPDATE_HSB ) // update HSB
    1234             :     {
    1235           0 :         maMFHue.SetValue( toInt( mdHue, 1.0 ) );
    1236           0 :         maMFSaturation.SetValue( toInt( mdSat, 100.0 ) );
    1237           0 :         maMFBrightness.SetValue( toInt( mdBri, 100.0 ) );
    1238             :     }
    1239             : 
    1240           0 :     if( n & UPDATE_COLORCHOOSER ) // update Color Chooser 1
    1241             :     {
    1242           0 :         switch( meMode )
    1243             :         {
    1244           0 :         case HUE:           maColorField.SetValues( aColor, meMode, mdSat, mdBri ); break;
    1245           0 :         case SATURATION:    maColorField.SetValues( aColor, meMode, mdHue / 360.0, mdBri ); break;
    1246           0 :         case BRIGHTNESS:    maColorField.SetValues( aColor, meMode, mdHue / 360.0, mdSat ); break;
    1247           0 :         case RED:           maColorField.SetValues( aColor, meMode, mdBlue, mdGreen ); break;
    1248           0 :         case GREEN:         maColorField.SetValues( aColor, meMode, mdBlue, mdRed ); break;
    1249           0 :         case BLUE:          maColorField.SetValues( aColor, meMode, mdRed, mdGreen ); break;
    1250             :         }
    1251             :     }
    1252             : 
    1253           0 :     if( n & UPDATE_COLORSLIDER ) // update Color Chooser 2
    1254             :     {
    1255           0 :         switch( meMode )
    1256             :         {
    1257           0 :         case HUE:           maColorSlider.SetValue( aColor, meMode, mdHue / 360.0 ); break;
    1258           0 :         case SATURATION:    maColorSlider.SetValue( aColor, meMode, mdSat ); break;
    1259           0 :         case BRIGHTNESS:    maColorSlider.SetValue( aColor, meMode, mdBri ); break;
    1260           0 :         case RED:           maColorSlider.SetValue( aColor, meMode, mdRed ); break;
    1261           0 :         case GREEN:         maColorSlider.SetValue( aColor, meMode, mdGreen ); break;
    1262           0 :         case BLUE:          maColorSlider.SetValue( aColor, meMode, mdBlue ); break;
    1263             :         }
    1264             :     }
    1265             : 
    1266           0 :     if( n & UPDATE_HEX ) // update hex
    1267             :     {
    1268           0 :         maEDHex.SetColor( aColor.GetColor()  );
    1269             :     }
    1270             : 
    1271             :     {
    1272           0 :         Point aPos( 0, maColorSlider.GetLevel() + maColorSlider.GetPosPixel().Y() - 1 );
    1273             : 
    1274           0 :         aPos.X() = maFISliderLeft.GetPosPixel().X();
    1275           0 :         if( aPos != maFISliderLeft.GetPosPixel() )
    1276             :         {
    1277           0 :             maFISliderLeft.SetPosPixel( aPos );
    1278             : 
    1279           0 :             aPos.X() = maFISliderRight.GetPosPixel().X();
    1280           0 :             maFISliderRight.SetPosPixel( aPos );
    1281             :         }
    1282             :     }
    1283             : 
    1284           0 :     maColorPreview.SetColor( aColor );
    1285           0 : }
    1286             : 
    1287             : // --------------------------------------------------------------------
    1288             : 
    1289           0 : IMPL_LINK( ColorPickerDialog, ColorModifyHdl, void *, p )
    1290             : {
    1291           0 :     sal_uInt16 n = 0;
    1292             : 
    1293           0 :     if( p == &maColorField )
    1294             :     {
    1295           0 :         double x = maColorField.GetX();
    1296           0 :         double y = maColorField.GetY();
    1297             : 
    1298           0 :         switch( meMode )
    1299             :         {
    1300           0 :         case HUE:           mdSat = x; setColorComponent( COLORCOMP_BRI, y ); break;
    1301           0 :         case SATURATION:    mdHue = x * 360.0; setColorComponent( COLORCOMP_BRI, y ); break;
    1302           0 :         case BRIGHTNESS:    mdHue = x * 360.0; setColorComponent( COLORCOMP_SAT, y ); break;
    1303           0 :         case RED:           mdBlue = x; setColorComponent( COLORCOMP_GREEN, y ); break;
    1304           0 :         case GREEN:         mdBlue = x; setColorComponent( COLORCOMP_RED, y ); break;
    1305           0 :         case BLUE:          mdRed = x; setColorComponent( COLORCOMP_GREEN, y ); break;
    1306             :         }
    1307             : 
    1308           0 :         n = UPDATE_ALL&~(UPDATE_COLORCHOOSER);
    1309             :     }
    1310           0 :     else if( p == &maColorSlider )
    1311             :     {
    1312           0 :         double dValue = maColorSlider.GetValue();
    1313           0 :         switch( meMode )
    1314             :         {
    1315           0 :         case HUE:           setColorComponent( COLORCOMP_HUE, dValue * 360.0 ); break;
    1316           0 :         case SATURATION:    setColorComponent( COLORCOMP_SAT, dValue ); break;
    1317           0 :         case BRIGHTNESS:    setColorComponent( COLORCOMP_BRI, dValue ); break;
    1318           0 :         case RED:           setColorComponent( COLORCOMP_RED, dValue ); break;
    1319           0 :         case GREEN:         setColorComponent( COLORCOMP_GREEN, dValue ); break;
    1320           0 :         case BLUE:          setColorComponent( COLORCOMP_BLUE, dValue ); break;
    1321             :         }
    1322             : 
    1323           0 :         n = UPDATE_ALL&~(UPDATE_COLORSLIDER);
    1324             :     }
    1325           0 :     else if( p == &maMFRed )
    1326             :     {
    1327           0 :         setColorComponent( COLORCOMP_RED, ((double)maMFRed.GetValue()) / 255.0 );
    1328           0 :         n = UPDATE_ALL&~(UPDATE_RGB);
    1329             :     }
    1330           0 :     else if( p == &maMFGreen )
    1331             :     {
    1332           0 :         setColorComponent( COLORCOMP_GREEN, ((double)maMFGreen.GetValue()) / 255.0 );
    1333           0 :         n = UPDATE_ALL&~(UPDATE_RGB);
    1334             :     }
    1335           0 :     else if( p == &maMFBlue )
    1336             :     {
    1337           0 :         setColorComponent( COLORCOMP_BLUE, ((double)maMFBlue.GetValue()) / 255.0 );
    1338           0 :         n = UPDATE_ALL&~(UPDATE_RGB);
    1339             :     }
    1340           0 :     else if( p == &maMFHue )
    1341             :     {
    1342           0 :         setColorComponent( COLORCOMP_HUE, (double)maMFHue.GetValue() );
    1343           0 :         n = UPDATE_ALL&~(UPDATE_HSB);
    1344             :     }
    1345           0 :     else if( p == &maMFSaturation )
    1346             :     {
    1347           0 :         setColorComponent( COLORCOMP_SAT, ((double)maMFSaturation.GetValue()) / 100.0 );
    1348           0 :         n = UPDATE_ALL&~(UPDATE_HSB);
    1349             :     }
    1350           0 :     else if( p == &maMFBrightness )
    1351             :     {
    1352           0 :         setColorComponent( COLORCOMP_BRI, ((double)maMFBrightness.GetValue()) / 100.0 );
    1353           0 :         n = UPDATE_ALL&~(UPDATE_HSB);
    1354             :     }
    1355           0 :     else if( p == &maMFCyan )
    1356             :     {
    1357           0 :         setColorComponent( COLORCOMP_CYAN, ((double)maMFCyan.GetValue()) / 100.0 );
    1358           0 :         n = UPDATE_ALL&~(UPDATE_CMYK);
    1359             :     }
    1360           0 :     else if( p == &maMFMagenta )
    1361             :     {
    1362           0 :         setColorComponent( COLORCOMP_MAGENTA, ((double)maMFMagenta.GetValue()) / 100.0 );
    1363           0 :         n = UPDATE_ALL&~(UPDATE_CMYK);
    1364             :     }
    1365           0 :     else if( p == &maMFYellow )
    1366             :     {
    1367           0 :         setColorComponent( COLORCOMP_YELLOW, ((double)maMFYellow.GetValue()) / 100.0 );
    1368           0 :         n = UPDATE_ALL&~(UPDATE_CMYK);
    1369             :     }
    1370           0 :     else if( p == &maMFKey )
    1371             :     {
    1372           0 :         setColorComponent( COLORCOMP_KEY, ((double)maMFKey.GetValue()) / 100.0 );
    1373           0 :         n = UPDATE_ALL&~(UPDATE_CMYK);
    1374             :     }
    1375           0 :     else if( p == &maEDHex )
    1376             :     {
    1377           0 :         sal_Int32 nColor = maEDHex.GetColor();
    1378             : 
    1379           0 :         if( nColor != -1 )
    1380             :         {
    1381           0 :             Color aColor( nColor );
    1382             : 
    1383           0 :             if( aColor != GetColor() )
    1384             :             {
    1385           0 :                 mdRed = ((double)aColor.GetRed()) / 255.0;
    1386           0 :                 mdGreen = ((double)aColor.GetGreen()) / 255.0;
    1387           0 :                 mdBlue = ((double)aColor.GetBlue()) / 255.0;
    1388             : 
    1389           0 :                 RGBtoHSV( mdRed, mdGreen, mdBlue, mdHue, mdSat, mdBri );
    1390           0 :                 RGBtoCMYK( mdRed, mdGreen, mdBlue, mdCyan, mdMagenta, mdYellow, mdKey );
    1391           0 :                 n = UPDATE_ALL&~(UPDATE_HEX);
    1392             :             }
    1393             :         }
    1394             :     }
    1395             : 
    1396           0 :     if( n )
    1397           0 :         update_color( n );
    1398             : 
    1399           0 :     return 0;
    1400             : }
    1401             : 
    1402             : // --------------------------------------------------------------------
    1403             : 
    1404           0 : IMPL_LINK_NOARG(ColorPickerDialog, ModeModifyHdl)
    1405             : {
    1406           0 :     ColorMode eMode = HUE;
    1407             : 
    1408           0 :     if( maRBRed.IsChecked() )
    1409             :     {
    1410           0 :         eMode = RED;
    1411             :     }
    1412           0 :     else if( maRBGreen.IsChecked() )
    1413             :     {
    1414           0 :         eMode = GREEN;
    1415             :     }
    1416           0 :     else if( maRBBlue.IsChecked() )
    1417             :     {
    1418           0 :         eMode = BLUE;
    1419             :     }
    1420           0 :     else if( maRBSaturation.IsChecked() )
    1421             :     {
    1422           0 :         eMode = SATURATION;
    1423             :     }
    1424           0 :     else if( maRBBrightness.IsChecked() )
    1425             :     {
    1426           0 :         eMode = BRIGHTNESS;
    1427             :     }
    1428             : 
    1429           0 :     if( meMode != eMode )
    1430             :     {
    1431           0 :         meMode = eMode;
    1432           0 :         update_color( UPDATE_COLORCHOOSER | UPDATE_COLORSLIDER );
    1433             :     }
    1434             : 
    1435           0 :     return 0;
    1436             : }
    1437             : 
    1438             : // --------------------------------------------------------------------
    1439             : 
    1440           0 : void ColorPickerDialog::setColorComponent( sal_uInt16 nComp, double dValue )
    1441             : {
    1442           0 :     switch( nComp )
    1443             :     {
    1444           0 :     case COLORCOMP_RED:     mdRed = dValue; break;
    1445           0 :     case COLORCOMP_GREEN:   mdGreen = dValue; break;
    1446           0 :     case COLORCOMP_BLUE:    mdBlue = dValue; break;
    1447           0 :     case COLORCOMP_HUE:     mdHue = dValue; break;
    1448           0 :     case COLORCOMP_SAT:     mdSat = dValue; break;
    1449           0 :     case COLORCOMP_BRI:     mdBri = dValue; break;
    1450           0 :     case COLORCOMP_CYAN:    mdCyan = dValue; break;
    1451           0 :     case COLORCOMP_YELLOW:  mdYellow = dValue; break;
    1452           0 :     case COLORCOMP_MAGENTA: mdMagenta = dValue; break;
    1453           0 :     case COLORCOMP_KEY:     mdKey = dValue; break;
    1454             :     }
    1455             : 
    1456           0 :     if( nComp & COLORMODE_RGB )
    1457             :     {
    1458           0 :         RGBtoHSV( mdRed, mdGreen, mdBlue, mdHue, mdSat, mdBri );
    1459           0 :         RGBtoCMYK( mdRed, mdGreen, mdBlue, mdCyan, mdMagenta, mdYellow, mdKey );
    1460             :     }
    1461           0 :     else if( nComp & COLORMODE_HSV )
    1462             :     {
    1463           0 :         HSVtoRGB( mdHue, mdSat, mdBri, mdRed, mdGreen, mdBlue );
    1464           0 :         RGBtoCMYK( mdRed, mdGreen, mdBlue, mdCyan, mdMagenta, mdYellow, mdKey );
    1465             :     }
    1466             :     else
    1467             :     {
    1468           0 :         CMYKtoRGB( mdCyan, mdMagenta, mdYellow, mdKey, mdRed, mdGreen, mdBlue );
    1469           0 :         RGBtoHSV( mdRed, mdGreen, mdBlue, mdHue, mdSat, mdBri );
    1470             :     }
    1471           0 : }
    1472             : 
    1473             : // --------------------------------------------------------------------
    1474             : 
    1475             : typedef ::cppu::WeakComponentImplHelper4< XServiceInfo, XExecutableDialog, XInitialization, XPropertyAccess > ColorPickerBase;
    1476             : 
    1477           0 : class ColorPicker : protected ::comphelper::OBaseMutex,    // Struct for right initalization of mutex member! Must be first of baseclasses.
    1478             :                     public ColorPickerBase
    1479             : {
    1480             : public:
    1481             :     ColorPicker( Reference< XComponentContext > const & xContext );
    1482             : 
    1483             :     // XInitialization
    1484             :     virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException);
    1485             : 
    1486             :     // XInitialization
    1487             :     virtual OUString SAL_CALL getImplementationName(  ) throw (RuntimeException);
    1488             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException);
    1489             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw (RuntimeException);
    1490             : 
    1491             :     // XPropertyAccess
    1492             :     virtual Sequence< PropertyValue > SAL_CALL getPropertyValues(  ) throw (RuntimeException);
    1493             :     virtual void SAL_CALL setPropertyValues( const Sequence< PropertyValue >& aProps ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
    1494             : 
    1495             :     // XExecutableDialog
    1496             :     virtual void SAL_CALL setTitle( const OUString& aTitle ) throw (RuntimeException);
    1497             :     virtual sal_Int16 SAL_CALL execute(  ) throw (RuntimeException);
    1498             : 
    1499             : private:
    1500             :     Reference< XComponentContext > mxContext;
    1501             :     OUString msTitle;
    1502             :     const OUString msColorKey;
    1503             :     const OUString msModeKey;
    1504             :     sal_Int32 mnColor;
    1505             :     sal_Int16 mnMode;
    1506             :     Reference< ::com::sun::star::awt::XWindow > mxParent;
    1507             : };
    1508             : 
    1509             : // --------------------------------------------------------------------
    1510             : 
    1511           0 : OUString SAL_CALL ColorPicker_getImplementationName()
    1512             : {
    1513           0 :     return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.cui.ColorPicker" ) );
    1514             : }
    1515             : 
    1516             : // --------------------------------------------------------------------
    1517             : 
    1518           0 : Reference< XInterface > SAL_CALL ColorPicker_createInstance( Reference< XComponentContext > const & xContext ) SAL_THROW( (Exception) )
    1519             : {
    1520           0 :     return static_cast<XWeak*>( new ColorPicker( xContext ) );
    1521             : }
    1522             : 
    1523             : // --------------------------------------------------------------------
    1524             : 
    1525           0 : Sequence< OUString > SAL_CALL ColorPicker_getSupportedServiceNames() throw( RuntimeException )
    1526             : {
    1527           0 :     Sequence< OUString > seq(1);
    1528           0 :     seq[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.ColorPicker" ) );
    1529           0 :     return seq;
    1530             : }
    1531             : 
    1532             : // --------------------------------------------------------------------
    1533             : 
    1534           0 : ColorPicker::ColorPicker( Reference< XComponentContext > const & xContext )
    1535             : : ColorPickerBase( m_aMutex )
    1536             : , mxContext( xContext )
    1537             : , msColorKey( RTL_CONSTASCII_USTRINGPARAM( "Color" ) )
    1538             : , msModeKey( RTL_CONSTASCII_USTRINGPARAM( "Mode" ) )
    1539             : , mnColor( 0 )
    1540           0 : , mnMode( 0 )
    1541             : {
    1542           0 : }
    1543             : 
    1544             : // --------------------------------------------------------------------
    1545             : 
    1546             : // XInitialization
    1547           0 : void SAL_CALL ColorPicker::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
    1548             : {
    1549           0 :     if( aArguments.getLength() == 1 )
    1550             :     {
    1551           0 :         aArguments[0] >>= mxParent;
    1552             :     }
    1553           0 : }
    1554             : 
    1555             : // --------------------------------------------------------------------
    1556             : 
    1557             : // XInitialization
    1558           0 : OUString SAL_CALL ColorPicker::getImplementationName(  ) throw (RuntimeException)
    1559             : {
    1560           0 :     return ColorPicker_getImplementationName();
    1561             : }
    1562             : 
    1563             : // --------------------------------------------------------------------
    1564             : 
    1565           0 : sal_Bool SAL_CALL ColorPicker::supportsService( const OUString& sServiceName ) throw (RuntimeException)
    1566             : {
    1567           0 :     return sServiceName == "com.sun.star.ui.dialogs.ColorPicker";
    1568             : }
    1569             : 
    1570             : // --------------------------------------------------------------------
    1571             : 
    1572           0 : Sequence< OUString > SAL_CALL ColorPicker::getSupportedServiceNames(  ) throw (RuntimeException)
    1573             : {
    1574           0 :     return ColorPicker_getSupportedServiceNames();
    1575             : }
    1576             : 
    1577             : // --------------------------------------------------------------------
    1578             : 
    1579             : // XPropertyAccess
    1580           0 : Sequence< PropertyValue > SAL_CALL ColorPicker::getPropertyValues(  ) throw (RuntimeException)
    1581             : {
    1582           0 :     Sequence< PropertyValue > props(1);
    1583           0 :     props[0].Name = msColorKey;
    1584           0 :     props[0].Value <<= mnColor;
    1585           0 :     return props;
    1586             : }
    1587             : 
    1588             : // --------------------------------------------------------------------
    1589             : 
    1590           0 : void SAL_CALL ColorPicker::setPropertyValues( const Sequence< PropertyValue >& aProps ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
    1591             : {
    1592           0 :     for( sal_Int32 n = 0; n < aProps.getLength(); n++ )
    1593             :     {
    1594           0 :         if( aProps[n].Name.equals( msColorKey ) )
    1595             :         {
    1596           0 :             aProps[n].Value >>= mnColor;
    1597             :         }
    1598           0 :         else if( aProps[n].Name.equals( msModeKey ) )
    1599             :         {
    1600           0 :             aProps[n].Value >>= mnMode;
    1601             :         }
    1602             :     }
    1603           0 : }
    1604             : 
    1605             : // --------------------------------------------------------------------
    1606             : 
    1607             : // XExecutableDialog
    1608           0 : void SAL_CALL ColorPicker::setTitle( const OUString& sTitle ) throw (RuntimeException)
    1609             : {
    1610           0 :     msTitle = sTitle;
    1611           0 : }
    1612             : 
    1613             : // --------------------------------------------------------------------
    1614             : 
    1615           0 : sal_Int16 SAL_CALL ColorPicker::execute(  ) throw (RuntimeException)
    1616             : {
    1617           0 :     ColorPickerDialog aDlg( VCLUnoHelper::GetWindow( mxParent ), mnColor, mnMode );
    1618           0 :     sal_Int16 ret = aDlg.Execute();
    1619           0 :     if( ret )
    1620           0 :         mnColor = aDlg.GetColor();
    1621             : 
    1622           0 :     return ret;
    1623             : }
    1624             : 
    1625             : // --------------------------------------------------------------------
    1626             : 
    1627             : }
    1628             : 
    1629             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10