LCOV - code coverage report
Current view: top level - libreoffice/extensions/source/scanner - grid.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 295 0.0 %
Date: 2012-12-27 Functions: 0 25 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 <grid.hrc>
      21             : #include <cstdio>
      22             : #include <math.h> // for M_LN10 and M_E
      23             : 
      24             : #define _USE_MATH_DEFINES
      25             : #include <cmath>
      26             : #undef _USE_MATH_DEFINES
      27             : 
      28             : #include <grid.hxx>
      29             : 
      30             : // for ::std::sort
      31             : #include <algorithm>
      32             : 
      33             : ResId SaneResId( sal_uInt32 );
      34             : 
      35             : /***********************************************************************
      36             :  *
      37             :  *  GridWindow
      38             :  *
      39             :  ***********************************************************************/
      40             : 
      41             : // ---------------------------------------------------------------------
      42             : 
      43           0 : GridWindow::GridWindow(double* pXValues, double* pYValues, int nValues, Window* pParent, sal_Bool bCutValues )
      44             : :   ModalDialog( pParent, SaneResId( GRID_DIALOG ) ),
      45             :     m_aGridArea( 50, 15, 100, 100 ),
      46             :     m_pXValues( pXValues ),
      47             :     m_pOrigYValues( pYValues ),
      48             :     m_nValues( nValues ),
      49             :     m_pNewYValues( NULL ),
      50             :     m_bCutValues( bCutValues ),
      51             :     m_aHandles(),
      52             :     m_nDragIndex( 0xffffffff ),
      53             :     m_aMarkerBitmap( Bitmap( SaneResId( GRID_DIALOG_HANDLE_BMP ) ), Color( 255, 255, 255 ) ),
      54             :     m_aOKButton( this, SaneResId( GRID_DIALOG_OK_BTN ) ),
      55             :     m_aCancelButton( this, SaneResId( GRID_DIALOG_CANCEL_BTN ) ),
      56             :     m_aResetTypeBox( this, SaneResId( GRID_DIALOG_TYPE_BOX ) ),
      57           0 :     m_aResetButton( this, SaneResId( GRID_DIALOG_RESET_BTN ) )
      58             : {
      59           0 :     sal_uInt16 nPos = m_aResetTypeBox.InsertEntry( String( SaneResId( RESET_TYPE_LINEAR_ASCENDING ) ) );
      60           0 :     m_aResetTypeBox.SetEntryData( nPos, (void *)RESET_TYPE_LINEAR_ASCENDING );
      61             : 
      62           0 :     nPos = m_aResetTypeBox.InsertEntry( String( SaneResId( RESET_TYPE_LINEAR_DESCENDING ) ) );
      63           0 :     m_aResetTypeBox.SetEntryData( nPos, (void *)RESET_TYPE_LINEAR_DESCENDING );
      64             : 
      65           0 :     nPos = m_aResetTypeBox.InsertEntry( String( SaneResId( RESET_TYPE_RESET ) ) );
      66           0 :     m_aResetTypeBox.SetEntryData( nPos, (void *)RESET_TYPE_RESET );
      67             : 
      68           0 :     nPos = m_aResetTypeBox.InsertEntry( String( SaneResId( RESET_TYPE_EXPONENTIAL ) ) );
      69           0 :     m_aResetTypeBox.SetEntryData( nPos, (void *)RESET_TYPE_EXPONENTIAL );
      70             : 
      71           0 :     m_aResetTypeBox.SelectEntryPos( 0 );
      72             : 
      73           0 :     m_aResetButton.SetClickHdl( LINK( this, GridWindow, ClickButtonHdl ) );
      74             : 
      75           0 :     SetMapMode( MapMode( MAP_PIXEL ) );
      76           0 :     Size aSize = GetOutputSizePixel();
      77           0 :     Size aBtnSize = m_aOKButton.GetOutputSizePixel();
      78           0 :     m_aGridArea.setWidth( aSize.Width() - aBtnSize.Width() - 80 );
      79           0 :     m_aGridArea.setHeight( aSize.Height() - 40 );
      80             : 
      81           0 :     if( m_pOrigYValues && m_nValues )
      82             :     {
      83           0 :         m_pNewYValues = new double[ m_nValues ];
      84           0 :         memcpy( m_pNewYValues, m_pOrigYValues, sizeof( double ) * m_nValues );
      85             :     }
      86             : 
      87           0 :     setBoundings( 0, 0, 1023, 1023 );
      88           0 :     computeExtremes();
      89             : 
      90             :     // create left and right marker as first and last entry
      91           0 :     m_BmOffX = sal_uInt16(m_aMarkerBitmap.GetSizePixel().Width() >> 1);
      92           0 :     m_BmOffY = sal_uInt16(m_aMarkerBitmap.GetSizePixel().Height() >> 1);
      93           0 :     m_aHandles.push_back(impHandle(transform(findMinX(), findMinY()), m_BmOffX, m_BmOffY));
      94           0 :     m_aHandles.push_back(impHandle(transform(findMaxX(), findMaxY()), m_BmOffX, m_BmOffY));
      95             : 
      96           0 :     FreeResource();
      97           0 : }
      98             : 
      99             : // ---------------------------------------------------------------------
     100             : 
     101           0 : GridWindow::~GridWindow()
     102             : {
     103           0 :     if( m_pNewYValues )
     104           0 :         delete [] m_pNewYValues;
     105           0 : }
     106             : 
     107             : // ---------------------------------------------------------------------
     108             : 
     109           0 : double GridWindow::findMinX()
     110             : {
     111           0 :     if( ! m_pXValues )
     112           0 :         return 0.0;
     113           0 :     double fMin = m_pXValues[0];
     114           0 :     for( int i = 1; i < m_nValues; i++ )
     115           0 :         if( m_pXValues[ i ] < fMin )
     116           0 :             fMin = m_pXValues[ i ];
     117           0 :     return fMin;
     118             : }
     119             : 
     120             : // ---------------------------------------------------------------------
     121             : 
     122           0 : double GridWindow::findMinY()
     123             : {
     124           0 :     if( ! m_pNewYValues )
     125           0 :         return 0.0;
     126           0 :     double fMin = m_pNewYValues[0];
     127           0 :     for( int i = 1; i < m_nValues; i++ )
     128           0 :         if( m_pNewYValues[ i ] < fMin )
     129           0 :             fMin = m_pNewYValues[ i ];
     130           0 :     return fMin;
     131             : }
     132             : 
     133             : // ---------------------------------------------------------------------
     134             : 
     135           0 : double GridWindow::findMaxX()
     136             : {
     137           0 :     if( ! m_pXValues )
     138           0 :         return 0.0;
     139           0 :     double fMax = m_pXValues[0];
     140           0 :     for( int i = 1; i < m_nValues; i++ )
     141           0 :         if( m_pXValues[ i ] > fMax )
     142           0 :             fMax = m_pXValues[ i ];
     143           0 :     return fMax;
     144             : }
     145             : 
     146             : // ---------------------------------------------------------------------
     147             : 
     148           0 : double GridWindow::findMaxY()
     149             : {
     150           0 :     if( ! m_pNewYValues )
     151           0 :         return 0.0;
     152           0 :     double fMax = m_pNewYValues[0];
     153           0 :     for( int i = 1; i < m_nValues; i++ )
     154           0 :         if( m_pNewYValues[ i ] > fMax )
     155           0 :             fMax = m_pNewYValues[ i ];
     156           0 :     return fMax;
     157             : }
     158             : 
     159             : // ---------------------------------------------------------------------
     160             : 
     161           0 : void GridWindow::computeExtremes()
     162             : {
     163           0 :     if( m_nValues && m_pXValues && m_pOrigYValues )
     164             :     {
     165           0 :         m_fMaxX = m_fMinX = m_pXValues[0];
     166           0 :         m_fMaxY = m_fMinY = m_pOrigYValues[0];
     167           0 :         for( int i = 1; i < m_nValues; i++ )
     168             :         {
     169           0 :             if( m_pXValues[ i ] > m_fMaxX )
     170           0 :                 m_fMaxX = m_pXValues[ i ];
     171           0 :             else if( m_pXValues[ i ] < m_fMinX )
     172           0 :                 m_fMinX = m_pXValues[ i ];
     173           0 :             if( m_pOrigYValues[ i ] > m_fMaxY )
     174           0 :                 m_fMaxY = m_pOrigYValues[ i ];
     175           0 :             else if( m_pOrigYValues[ i ] < m_fMinY )
     176           0 :                 m_fMinY = m_pOrigYValues[ i ];
     177             :         }
     178           0 :         setBoundings( m_fMinX, m_fMinY, m_fMaxX, m_fMaxY );
     179             :     }
     180           0 : }
     181             : 
     182             : // ---------------------------------------------------------------------
     183             : 
     184           0 : Point GridWindow::transform( double x, double y )
     185             : {
     186           0 :     Point aRet;
     187             : 
     188           0 :     aRet.X() = (long)( ( x - m_fMinX ) *
     189           0 :         (double)m_aGridArea.GetWidth() / ( m_fMaxX - m_fMinX )
     190           0 :         + m_aGridArea.Left() );
     191           0 :     aRet.Y() = (long)(
     192           0 :         m_aGridArea.Bottom() -
     193             :         ( y - m_fMinY ) *
     194           0 :         (double)m_aGridArea.GetHeight() / ( m_fMaxY - m_fMinY ) );
     195           0 :     return aRet;
     196             : }
     197             : 
     198             : // ---------------------------------------------------------------------
     199             : 
     200           0 : void GridWindow::transform( const Point& rOriginal, double& x, double& y )
     201             : {
     202           0 :     x = ( rOriginal.X() - m_aGridArea.Left() ) * (m_fMaxX - m_fMinX) / (double)m_aGridArea.GetWidth() + m_fMinX;
     203           0 :     y = ( m_aGridArea.Bottom() - rOriginal.Y() ) * (m_fMaxY - m_fMinY) / (double)m_aGridArea.GetHeight() + m_fMinY;
     204           0 : }
     205             : 
     206             : // ---------------------------------------------------------------------
     207             : 
     208           0 : void GridWindow::drawLine( double x1, double y1, double x2, double y2 )
     209             : {
     210           0 :     DrawLine( transform( x1, y1 ), transform( x2, y2 ) );
     211           0 : }
     212             : 
     213             : // ---------------------------------------------------------------------
     214             : 
     215           0 : void GridWindow::computeChunk( double fMin, double fMax, double& fChunkOut, double& fMinChunkOut )
     216             : {
     217             :     // get a nice chunk size like 10, 100, 25 or such
     218           0 :     fChunkOut = ( fMax - fMin ) / 6.0;
     219           0 :     int logchunk = (int)std::log10( fChunkOut );
     220           0 :     int nChunk = (int)( fChunkOut / std::exp( (double)(logchunk-1) * M_LN10 ) );
     221           0 :     if( nChunk >= 75 )
     222           0 :         nChunk = 100;
     223           0 :     else if( nChunk >= 35 )
     224           0 :         nChunk = 50;
     225           0 :     else if ( nChunk > 20 )
     226           0 :         nChunk = 25;
     227           0 :     else if ( nChunk >= 13 )
     228           0 :         nChunk = 20;
     229           0 :     else if( nChunk > 5 )
     230           0 :         nChunk = 10;
     231             :     else
     232           0 :         nChunk = 5;
     233           0 :     fChunkOut = (double) nChunk * exp( (double)(logchunk-1) * M_LN10 );
     234             :     // compute whole chunks fitting into fMin
     235           0 :     nChunk = (int)( fMin / fChunkOut );
     236           0 :     fMinChunkOut = (double)nChunk * fChunkOut;
     237           0 :     while( fMinChunkOut < fMin )
     238           0 :         fMinChunkOut += fChunkOut;
     239           0 : }
     240             : 
     241             : // ---------------------------------------------------------------------
     242             : 
     243           0 : void GridWindow::computeNew()
     244             : {
     245           0 :     if(2L == m_aHandles.size())
     246             :     {
     247             :         // special case: only left and right markers
     248             :         double xleft, yleft;
     249             :         double xright, yright;
     250           0 :         transform(m_aHandles[0L].maPos, xleft, yleft);
     251           0 :         transform(m_aHandles[1L].maPos, xright, yright );
     252           0 :         double factor = (yright-yleft)/(xright-xleft);
     253           0 :         for( int i = 0; i < m_nValues; i++ )
     254             :         {
     255           0 :             m_pNewYValues[ i ] = yleft + ( m_pXValues[ i ] - xleft )*factor;
     256             :         }
     257             :     }
     258             :     else
     259             :     {
     260             :         // sort markers
     261           0 :         std::sort(m_aHandles.begin(), m_aHandles.end());
     262           0 :         const int nSorted = m_aHandles.size();
     263             :         int i;
     264             : 
     265             :         // get node arrays
     266           0 :         double* nodex = new double[ nSorted ];
     267           0 :         double* nodey = new double[ nSorted ];
     268             : 
     269           0 :         for( i = 0L; i < nSorted; i++ )
     270           0 :             transform( m_aHandles[i].maPos, nodex[ i ], nodey[ i ] );
     271             : 
     272           0 :         for( i = 0; i < m_nValues; i++ )
     273             :         {
     274           0 :             double x = m_pXValues[ i ];
     275           0 :             m_pNewYValues[ i ] = interpolate( x, nodex, nodey, nSorted );
     276           0 :             if( m_bCutValues )
     277             :             {
     278           0 :                 if( m_pNewYValues[ i ] > m_fMaxY )
     279           0 :                     m_pNewYValues[ i ] = m_fMaxY;
     280           0 :                 else if( m_pNewYValues[ i ] < m_fMinY )
     281           0 :                     m_pNewYValues[ i ] = m_fMinY;
     282             :             }
     283             :         }
     284             : 
     285           0 :         delete [] nodex;
     286           0 :         delete [] nodey;
     287             :     }
     288           0 : }
     289             : 
     290             : // ---------------------------------------------------------------------
     291             : 
     292           0 : double GridWindow::interpolate(
     293             :     double x,
     294             :     double* pNodeX,
     295             :     double* pNodeY,
     296             :     int nNodes )
     297             : {
     298             :     // compute Lagrange interpolation
     299           0 :     double ret = 0;
     300           0 :     for( int i = 0; i < nNodes; i++ )
     301             :     {
     302           0 :         double sum = pNodeY[ i ];
     303           0 :         for( int n = 0; n < nNodes; n++ )
     304             :         {
     305           0 :             if( n != i )
     306             :             {
     307           0 :                 sum *= x - pNodeX[ n ];
     308           0 :                 sum /= pNodeX[ i ] - pNodeX[ n ];
     309             :             }
     310             :         }
     311           0 :         ret += sum;
     312             :     }
     313           0 :     return ret;
     314             : }
     315             : 
     316             : // ---------------------------------------------------------------------
     317             : 
     318           0 : void GridWindow::setBoundings( double fMinX, double fMinY, double fMaxX, double fMaxY )
     319             : {
     320           0 :     m_fMinX = fMinX;
     321           0 :     m_fMinY = fMinY;
     322           0 :     m_fMaxX = fMaxX;
     323           0 :     m_fMaxY = fMaxY;
     324             : 
     325           0 :     computeChunk( m_fMinX, m_fMaxX, m_fChunkX, m_fMinChunkX );
     326           0 :     computeChunk( m_fMinY, m_fMaxY, m_fChunkY, m_fMinChunkY );
     327           0 : }
     328             : 
     329             : // ---------------------------------------------------------------------
     330             : 
     331           0 : void GridWindow::drawGrid()
     332             : {
     333             :     char pBuf[256];
     334           0 :     SetLineColor( Color( COL_BLACK ) );
     335             :     // draw vertical lines
     336           0 :     for( double fX = m_fMinChunkX; fX < m_fMaxX; fX += m_fChunkX )
     337             :     {
     338           0 :         drawLine( fX, m_fMinY, fX, m_fMaxY );
     339             :         // draw tickmarks
     340           0 :         Point aPt = transform( fX, m_fMinY );
     341           0 :         std::sprintf( pBuf, "%g", fX );
     342           0 :         String aMark( pBuf, osl_getThreadTextEncoding() );
     343           0 :         Size aTextSize( GetTextWidth( aMark ), GetTextHeight() );
     344           0 :         aPt.X() -= aTextSize.Width()/2;
     345           0 :         aPt.Y() += aTextSize.Height()/2;
     346           0 :         DrawText( aPt, aMark );
     347           0 :     }
     348             :     // draw horizontal lines
     349           0 :     for( double fY = m_fMinChunkY; fY < m_fMaxY; fY += m_fChunkY )
     350             :     {
     351           0 :         drawLine( m_fMinX, fY, m_fMaxX, fY );
     352             :         // draw tickmarks
     353           0 :         Point aPt = transform( m_fMinX, fY );
     354           0 :         std::sprintf( pBuf, "%g", fY );
     355           0 :         String aMark( pBuf, osl_getThreadTextEncoding() );
     356           0 :         Size aTextSize( GetTextWidth( aMark ), GetTextHeight() );
     357           0 :         aPt.X() -= aTextSize.Width() + 2;
     358           0 :         aPt.Y() -= aTextSize.Height()/2;
     359           0 :         DrawText( aPt, aMark );
     360           0 :     }
     361             : 
     362             :     // draw boundings
     363           0 :     drawLine( m_fMinX, m_fMinY, m_fMaxX, m_fMinY );
     364           0 :     drawLine( m_fMinX, m_fMaxY, m_fMaxX, m_fMaxY );
     365           0 :     drawLine( m_fMinX, m_fMinY, m_fMinX, m_fMaxY );
     366           0 :     drawLine( m_fMaxX, m_fMinY, m_fMaxX, m_fMaxY );
     367           0 : }
     368             : 
     369             : // ---------------------------------------------------------------------
     370             : 
     371           0 : void GridWindow::drawOriginal()
     372             : {
     373           0 :     if( m_nValues && m_pXValues && m_pOrigYValues )
     374             :     {
     375           0 :         SetLineColor( Color( COL_RED ) );
     376           0 :         for( int i = 0; i < m_nValues-1; i++ )
     377             :         {
     378           0 :             drawLine( m_pXValues[ i   ], m_pOrigYValues[ i   ],
     379           0 :                       m_pXValues[ i+1 ], m_pOrigYValues[ i+1 ] );
     380             :         }
     381             :     }
     382           0 : }
     383             : 
     384             : // ---------------------------------------------------------------------
     385             : 
     386           0 : void GridWindow::drawNew()
     387             : {
     388           0 :     if( m_nValues && m_pXValues && m_pNewYValues )
     389             :     {
     390           0 :         SetClipRegion( m_aGridArea );
     391           0 :         SetLineColor( Color( COL_YELLOW ) );
     392           0 :         for( int i = 0; i < m_nValues-1; i++ )
     393             :         {
     394           0 :             drawLine( m_pXValues[ i   ], m_pNewYValues[ i   ],
     395           0 :                       m_pXValues[ i+1 ], m_pNewYValues[ i+1 ] );
     396             :         }
     397           0 :         SetClipRegion();
     398             :     }
     399           0 : }
     400             : 
     401             : // ---------------------------------------------------------------------
     402             : 
     403           0 : void GridWindow::drawHandles()
     404             : {
     405           0 :     for(sal_uInt32 i(0L); i < m_aHandles.size(); i++)
     406             :     {
     407           0 :         m_aHandles[i].draw(*this, m_aMarkerBitmap);
     408             :     }
     409           0 : }
     410             : 
     411             : // ---------------------------------------------------------------------
     412             : 
     413           0 : void GridWindow::Paint( const Rectangle& rRect )
     414             : {
     415           0 :     ModalDialog::Paint( rRect );
     416           0 :     drawGrid();
     417           0 :     drawOriginal();
     418           0 :     drawNew();
     419           0 :     drawHandles();
     420           0 : }
     421             : 
     422             : // ---------------------------------------------------------------------
     423             : 
     424           0 : void GridWindow::MouseMove( const MouseEvent& rEvt )
     425             : {
     426           0 :     if( rEvt.GetButtons() == MOUSE_LEFT && m_nDragIndex != 0xffffffff )
     427             :     {
     428           0 :         Point aPoint( rEvt.GetPosPixel() );
     429             : 
     430           0 :         if( m_nDragIndex == 0L || m_nDragIndex == m_aHandles.size() - 1L)
     431             :         {
     432           0 :             aPoint.X() = m_aHandles[m_nDragIndex].maPos.X();
     433             :         }
     434             :         else
     435             :         {
     436           0 :             if(aPoint.X() < m_aGridArea.Left())
     437           0 :                 aPoint.X() = m_aGridArea.Left();
     438           0 :             else if(aPoint.X() > m_aGridArea.Right())
     439           0 :                 aPoint.X() = m_aGridArea.Right();
     440             :         }
     441             : 
     442           0 :         if( aPoint.Y() < m_aGridArea.Top() )
     443           0 :             aPoint.Y() = m_aGridArea.Top();
     444           0 :         else if( aPoint.Y() > m_aGridArea.Bottom() )
     445           0 :             aPoint.Y() = m_aGridArea.Bottom();
     446             : 
     447           0 :         if( aPoint != m_aHandles[m_nDragIndex].maPos )
     448             :         {
     449           0 :             m_aHandles[m_nDragIndex].maPos = aPoint;
     450           0 :             Invalidate( m_aGridArea );
     451             :         }
     452             :     }
     453             : 
     454           0 :     ModalDialog::MouseMove( rEvt );
     455           0 : }
     456             : 
     457             : // ---------------------------------------------------------------------
     458             : 
     459           0 : void GridWindow::MouseButtonUp( const MouseEvent& rEvt )
     460             : {
     461           0 :     if( rEvt.GetButtons() == MOUSE_LEFT )
     462             :     {
     463           0 :         if( m_nDragIndex != 0xffffffff )
     464             :         {
     465           0 :             m_nDragIndex = 0xffffffff;
     466           0 :             computeNew();
     467           0 :             Invalidate( m_aGridArea );
     468           0 :             Paint( m_aGridArea );
     469             :         }
     470             :     }
     471             : 
     472           0 :     ModalDialog::MouseButtonUp( rEvt );
     473           0 : }
     474             : 
     475             : // ---------------------------------------------------------------------
     476             : 
     477           0 : void GridWindow::MouseButtonDown( const MouseEvent& rEvt )
     478             : {
     479           0 :     Point aPoint( rEvt.GetPosPixel() );
     480           0 :     sal_uInt32 nMarkerIndex = 0xffffffff;
     481             : 
     482           0 :     for(sal_uInt32 a(0L); nMarkerIndex == 0xffffffff && a < m_aHandles.size(); a++)
     483             :     {
     484           0 :         if(m_aHandles[a].isHit(*this, aPoint))
     485             :         {
     486           0 :             nMarkerIndex = a;
     487             :         }
     488             :     }
     489             : 
     490           0 :     if( rEvt.GetButtons() == MOUSE_LEFT )
     491             :     {
     492             :         // user wants to drag a button
     493           0 :         if( nMarkerIndex != 0xffffffff )
     494             :         {
     495           0 :             m_nDragIndex = nMarkerIndex;
     496             :         }
     497             :     }
     498           0 :     else if( rEvt.GetButtons() == MOUSE_RIGHT )
     499             :     {
     500             :         // user wants to add/delete a button
     501           0 :         if( nMarkerIndex != 0xffffffff )
     502             :         {
     503           0 :             if( nMarkerIndex != 0L && nMarkerIndex != m_aHandles.size() - 1L)
     504             :             {
     505             :                 // delete marker under mouse
     506           0 :                 if( m_nDragIndex == nMarkerIndex )
     507           0 :                     m_nDragIndex = 0xffffffff;
     508             : 
     509           0 :                 m_aHandles.erase(m_aHandles.begin() + nMarkerIndex);
     510             :             }
     511             :         }
     512             :         else
     513             :         {
     514           0 :             m_BmOffX = sal_uInt16(m_aMarkerBitmap.GetSizePixel().Width() >> 1);
     515           0 :             m_BmOffY = sal_uInt16(m_aMarkerBitmap.GetSizePixel().Height() >> 1);
     516           0 :             m_aHandles.push_back(impHandle(aPoint, m_BmOffX, m_BmOffY));
     517             :         }
     518             : 
     519           0 :         computeNew();
     520           0 :         Invalidate( m_aGridArea );
     521           0 :         Paint( m_aGridArea );
     522             :     }
     523             : 
     524           0 :     ModalDialog::MouseButtonDown( rEvt );
     525           0 : }
     526             : 
     527             : // ---------------------------------------------------------------------
     528             : 
     529           0 : IMPL_LINK( GridWindow, ClickButtonHdl, Button*, pButton )
     530             : {
     531           0 :     if( pButton == &m_aResetButton )
     532             :     {
     533           0 :         int nType = (int)(sal_IntPtr)m_aResetTypeBox.GetEntryData( m_aResetTypeBox.GetSelectEntryPos() );
     534           0 :         switch( nType )
     535             :         {
     536             :             case RESET_TYPE_LINEAR_ASCENDING:
     537             :             {
     538           0 :                 for( int i = 0; i < m_nValues; i++ )
     539             :                 {
     540           0 :                     m_pNewYValues[ i ] = m_fMinY + (m_fMaxY-m_fMinY)/(m_fMaxX-m_fMinX)*(m_pXValues[i]-m_fMinX);
     541             :                 }
     542             :             }
     543           0 :             break;
     544             :             case RESET_TYPE_LINEAR_DESCENDING:
     545             :             {
     546           0 :                 for( int i = 0; i < m_nValues; i++ )
     547             :                 {
     548           0 :                     m_pNewYValues[ i ] = m_fMaxY - (m_fMaxY-m_fMinY)/(m_fMaxX-m_fMinX)*(m_pXValues[i]-m_fMinX);
     549             :                 }
     550             :             }
     551           0 :             break;
     552             :             case RESET_TYPE_RESET:
     553             :             {
     554           0 :                 if( m_pOrigYValues && m_pNewYValues && m_nValues )
     555           0 :                     memcpy( m_pNewYValues, m_pOrigYValues, m_nValues*sizeof(double) );
     556             :             }
     557           0 :             break;
     558             :             case RESET_TYPE_EXPONENTIAL:
     559             :             {
     560           0 :                 for( int i = 0; i < m_nValues; i++ )
     561             :                 {
     562           0 :                     m_pNewYValues[ i ] = m_fMinY + (m_fMaxY-m_fMinY)*(std::exp((m_pXValues[i]-m_fMinX)/(m_fMaxX-m_fMinX))-1.0)/(M_E-1.0);
     563             :                 }
     564             :             }
     565           0 :             break;
     566             : 
     567             :             default:
     568           0 :                 break;
     569             :         }
     570             : 
     571           0 :         for(sal_uInt32 i(0L); i < m_aHandles.size(); i++)
     572             :         {
     573             :             // find nearest xvalue
     574             :             double x, y;
     575           0 :             transform( m_aHandles[i].maPos, x, y );
     576           0 :             int nIndex = 0;
     577           0 :             double delta = std::fabs( x-m_pXValues[0] );
     578           0 :             for( int n = 1; n < m_nValues; n++ )
     579             :             {
     580           0 :                 if( delta > std::fabs( x - m_pXValues[ n ] ) )
     581             :                 {
     582           0 :                     delta = std::fabs( x - m_pXValues[ n ] );
     583           0 :                     nIndex = n;
     584             :                 }
     585             :             }
     586           0 :             if( 0 == i )
     587           0 :                 m_aHandles[i].maPos = transform( m_fMinX, m_pNewYValues[ nIndex ] );
     588           0 :             else if( m_aHandles.size() - 1L == i )
     589           0 :                 m_aHandles[i].maPos = transform( m_fMaxX, m_pNewYValues[ nIndex ] );
     590             :             else
     591           0 :                 m_aHandles[i].maPos = transform( m_pXValues[ nIndex ], m_pNewYValues[ nIndex ] );
     592             :         }
     593             : 
     594           0 :         Invalidate( m_aGridArea );
     595           0 :         Paint(Rectangle());
     596             :     }
     597           0 :     return 0;
     598             : }
     599             : 
     600             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10