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

Generated by: LCOV version 1.10