LCOV - code coverage report
Current view: top level - vcl/source/control - spinfld.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 262 556 47.1 %
Date: 2012-08-25 Functions: 20 36 55.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 203 765 26.5 %

           Branch data     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                 :            : 
      21                 :            : #include "tools/rc.h"
      22                 :            : 
      23                 :            : #include "vcl/event.hxx"
      24                 :            : #include "vcl/decoview.hxx"
      25                 :            : #include "vcl/spin.h"
      26                 :            : #include "vcl/spinfld.hxx"
      27                 :            : 
      28                 :            : #include "controldata.hxx"
      29                 :            : #include "svdata.hxx"
      30                 :            : 
      31                 :            : // =======================================================================
      32                 :            : 
      33                 :        707 : void ImplGetSpinbuttonValue( Window *pWin, const Rectangle& rUpperRect,
      34                 :            :                             const Rectangle& rLowerRect,
      35                 :            :                             sal_Bool bUpperIn, sal_Bool bLowerIn,
      36                 :            :                             sal_Bool bUpperEnabled, sal_Bool bLowerEnabled, sal_Bool bHorz,
      37                 :            :                             SpinbuttonValue& rValue )
      38                 :            : {
      39                 :            :     // convert spinbutton data to a SpinbuttonValue structure for native painting
      40                 :            : 
      41                 :        707 :     rValue.maUpperRect = rUpperRect;
      42                 :        707 :     rValue.maLowerRect = rLowerRect;
      43                 :            : 
      44         [ +  - ]:        707 :     Point aPointerPos = pWin->GetPointerPosPixel();
      45                 :            : 
      46                 :        707 :     ControlState nState = CTRL_STATE_ENABLED;
      47         [ -  + ]:        707 :     if ( bUpperIn )
      48                 :          0 :         nState |= CTRL_STATE_PRESSED;
      49 [ +  - ][ +  + ]:        707 :     if ( !pWin->IsEnabled() || !bUpperEnabled )
         [ -  + ][ +  + ]
      50                 :        247 :         nState &= ~CTRL_STATE_ENABLED;
      51 [ +  - ][ -  + ]:        707 :     if ( pWin->HasFocus() )
      52                 :          0 :         nState |= CTRL_STATE_FOCUSED;
      53 [ +  - ][ -  + ]:        707 :     if( pWin->IsMouseOver() && rUpperRect.IsInside( aPointerPos ) )
         [ #  # ][ #  # ]
                 [ -  + ]
      54                 :          0 :         nState |= CTRL_STATE_ROLLOVER;
      55                 :        707 :     rValue.mnUpperState = nState;
      56                 :            : 
      57                 :        707 :     nState = CTRL_STATE_ENABLED;
      58         [ -  + ]:        707 :     if ( bLowerIn )
      59                 :          0 :         nState |= CTRL_STATE_PRESSED;
      60 [ +  - ][ +  + ]:        707 :     if ( !pWin->IsEnabled() || !bLowerEnabled )
         [ +  + ][ +  + ]
      61                 :        252 :         nState &= ~CTRL_STATE_ENABLED;
      62 [ +  - ][ -  + ]:        707 :     if ( pWin->HasFocus() )
      63                 :          0 :         nState |= CTRL_STATE_FOCUSED;
      64                 :            :     // for overlapping spins: highlight only one
      65 [ +  - ][ -  + ]:        707 :     if( pWin->IsMouseOver() && rLowerRect.IsInside( aPointerPos ) &&
         [ #  # ][ #  # ]
         [ #  # ][ -  + ]
      66         [ #  # ]:          0 :                               !rUpperRect.IsInside( aPointerPos ) )
      67                 :          0 :         nState |= CTRL_STATE_ROLLOVER;
      68                 :        707 :     rValue.mnLowerState = nState;
      69                 :            : 
      70         [ +  + ]:        707 :     rValue.mnUpperPart = bHorz ? PART_BUTTON_LEFT : PART_BUTTON_UP;
      71         [ +  + ]:        707 :     rValue.mnLowerPart = bHorz ? PART_BUTTON_RIGHT : PART_BUTTON_DOWN;
      72                 :        707 : }
      73                 :            : 
      74                 :            : 
      75                 :        702 : sal_Bool ImplDrawNativeSpinfield( Window *pWin, const SpinbuttonValue& rSpinbuttonValue )
      76                 :            : {
      77                 :        702 :     sal_Bool bNativeOK = sal_False;
      78                 :            : 
      79   [ -  +  #  # ]:        702 :     if( pWin->IsNativeControlSupported(CTRL_SPINBOX, PART_ENTIRE_CONTROL) &&
                 [ -  + ]
      80                 :            :         // there is just no useful native support for spinfields with dropdown
      81                 :          0 :         !(pWin->GetStyle() & WB_DROPDOWN) )
      82                 :            :     {
      83   [ #  #  #  # ]:          0 :         if( pWin->IsNativeControlSupported(CTRL_SPINBOX, rSpinbuttonValue.mnUpperPart) &&
                 [ #  # ]
      84                 :          0 :             pWin->IsNativeControlSupported(CTRL_SPINBOX, rSpinbuttonValue.mnLowerPart) )
      85                 :            :         {
      86                 :            :             // only paint the embedded spin buttons, all buttons are painted at once
      87                 :            :             bNativeOK = pWin->DrawNativeControl( CTRL_SPINBOX, PART_ALL_BUTTONS, Rectangle(), CTRL_STATE_ENABLED,
      88 [ #  # ][ #  # ]:          0 :                         rSpinbuttonValue, rtl::OUString() );
      89                 :            :         }
      90                 :            :         else
      91                 :            :         {
      92                 :            :             // paint the spinbox as a whole, use borderwindow to have proper clipping
      93         [ #  # ]:          0 :             Window *pBorder = pWin->GetWindow( WINDOW_BORDER );
      94                 :            : 
      95                 :            :             // to not overwrite everything, set the button region as clipregion to the border window
      96                 :          0 :             Rectangle aClipRect( rSpinbuttonValue.maLowerRect );
      97         [ #  # ]:          0 :             aClipRect.Union( rSpinbuttonValue.maUpperRect );
      98                 :            : 
      99                 :            :             // convert from screen space to borderwin space
     100 [ #  # ][ #  # ]:          0 :             aClipRect.SetPos( pBorder->ScreenToOutputPixel(pWin->OutputToScreenPixel(aClipRect.TopLeft())) );
     101                 :            : 
     102         [ #  # ]:          0 :             Region oldRgn( pBorder->GetClipRegion() );
     103 [ #  # ][ #  # ]:          0 :             pBorder->SetClipRegion( Region( aClipRect ) );
                 [ #  # ]
     104                 :            : 
     105                 :          0 :             Point aPt;
     106                 :          0 :             Size aSize( pBorder->GetOutputSizePixel() );    // the size of the border window, i.e., the whole control
     107 [ #  # ][ #  # ]:          0 :             Rectangle aBound, aContent;
     108         [ #  # ]:          0 :             Rectangle aNatRgn( aPt, aSize );
     109 [ #  # ][ #  # ]:          0 :             if( ! ImplGetSVData()->maNWFData.mbCanDrawWidgetAnySize &&
         [ #  # ][ #  # ]
     110                 :            :                 pBorder->GetNativeControlRegion( CTRL_SPINBOX, PART_ENTIRE_CONTROL,
     111 [ #  # ][ #  # ]:          0 :                                                  aNatRgn, 0, rSpinbuttonValue, rtl::OUString(), aBound, aContent) )
                 [ #  # ]
     112                 :            :             {
     113         [ #  # ]:          0 :                 aSize = aContent.GetSize();
     114                 :            :             }
     115                 :            : 
     116         [ #  # ]:          0 :             Rectangle aRgn( aPt, aSize );
     117                 :            :             bNativeOK = pBorder->DrawNativeControl( CTRL_SPINBOX, PART_ENTIRE_CONTROL, aRgn, CTRL_STATE_ENABLED,
     118         [ #  # ]:          0 :                         rSpinbuttonValue, rtl::OUString() );
     119                 :            : 
     120 [ #  # ][ #  # ]:          0 :             pBorder->SetClipRegion( oldRgn );
     121                 :            :         }
     122                 :            :     }
     123                 :        702 :     return bNativeOK;
     124                 :            : }
     125                 :            : 
     126                 :          5 : sal_Bool ImplDrawNativeSpinbuttons( Window *pWin, const SpinbuttonValue& rSpinbuttonValue )
     127                 :            : {
     128                 :          5 :     sal_Bool bNativeOK = sal_False;
     129                 :            : 
     130         [ -  + ]:          5 :     if( pWin->IsNativeControlSupported(CTRL_SPINBUTTONS, PART_ENTIRE_CONTROL) )
     131                 :            :     {
     132                 :            :         // only paint the standalone spin buttons, all buttons are painted at once
     133                 :            :         bNativeOK = pWin->DrawNativeControl( CTRL_SPINBUTTONS, PART_ALL_BUTTONS, Rectangle(), CTRL_STATE_ENABLED,
     134 [ #  # ][ #  # ]:          0 :                     rSpinbuttonValue, rtl::OUString() );
     135                 :            :     }
     136                 :          5 :     return bNativeOK;
     137                 :            : }
     138                 :            : 
     139                 :        707 : void ImplDrawSpinButton( OutputDevice* pOutDev,
     140                 :            :                          const Rectangle& rUpperRect,
     141                 :            :                          const Rectangle& rLowerRect,
     142                 :            :                          sal_Bool bUpperIn, sal_Bool bLowerIn,
     143                 :            :                          sal_Bool bUpperEnabled, sal_Bool bLowerEnabled, sal_Bool bHorz, sal_Bool bMirrorHorz )
     144                 :            : {
     145                 :        707 :     DecorationView aDecoView( pOutDev );
     146                 :            : 
     147                 :        707 :     sal_uInt16 nStyle = BUTTON_DRAW_NOLEFTLIGHTBORDER;
     148                 :        707 :     sal_uInt16 nSymStyle = 0;
     149                 :            : 
     150                 :            :     SymbolType eType1, eType2;
     151                 :            : 
     152                 :        707 :     const StyleSettings& rStyleSettings = pOutDev->GetSettings().GetStyleSettings();
     153         [ -  + ]:        707 :     if ( rStyleSettings.GetOptions() & STYLE_OPTION_SPINARROW )
     154                 :            :     {
     155                 :            :         // arrows are only use in OS/2 look
     156         [ #  # ]:          0 :         if ( bHorz )
     157                 :            :         {
     158         [ #  # ]:          0 :             eType1 = bMirrorHorz ? SYMBOL_ARROW_RIGHT : SYMBOL_ARROW_LEFT;
     159         [ #  # ]:          0 :             eType2 = bMirrorHorz ? SYMBOL_ARROW_LEFT : SYMBOL_ARROW_RIGHT;
     160                 :            :         }
     161                 :            :         else
     162                 :            :         {
     163                 :          0 :             eType1 = SYMBOL_ARROW_UP;
     164                 :          0 :             eType2 = SYMBOL_ARROW_DOWN;
     165                 :            :         }
     166                 :            :     }
     167                 :            :     else
     168                 :            :     {
     169         [ +  + ]:        707 :         if ( bHorz )
     170                 :            :         {
     171         [ +  - ]:          5 :             eType1 = bMirrorHorz ? SYMBOL_SPIN_RIGHT : SYMBOL_SPIN_LEFT;
     172         [ +  - ]:          5 :             eType2 = bMirrorHorz ? SYMBOL_SPIN_LEFT : SYMBOL_SPIN_RIGHT;
     173                 :            :         }
     174                 :            :         else
     175                 :            :         {
     176                 :        702 :             eType1 = SYMBOL_SPIN_UP;
     177                 :        702 :             eType2 = SYMBOL_SPIN_DOWN;
     178                 :            :         }
     179                 :            :     }
     180                 :            : 
     181                 :            :     // Oberen/linken Button malen
     182                 :        707 :     sal_uInt16 nTempStyle = nStyle;
     183         [ -  + ]:        707 :     if ( bUpperIn )
     184                 :          0 :         nTempStyle |= BUTTON_DRAW_PRESSED;
     185                 :            : 
     186                 :        707 :     sal_Bool bNativeOK = sal_False;
     187         [ +  - ]:        707 :     Rectangle aUpRect;
     188                 :            : 
     189         [ +  - ]:        707 :     if( pOutDev->GetOutDevType() == OUTDEV_WINDOW )
     190                 :            :     {
     191                 :        707 :         Window *pWin = (Window*) pOutDev;
     192                 :            : 
     193                 :            :         // are we drawing standalone spin buttons or members of a spinfield ?
     194                 :        707 :         ControlType aControl = CTRL_SPINBUTTONS;
     195 [ +  - ][ +  + ]:        707 :         switch( pWin->GetType() )
     196                 :            :         {
     197                 :            :             case WINDOW_EDIT:
     198                 :            :             case WINDOW_MULTILINEEDIT:
     199                 :            :             case WINDOW_PATTERNFIELD:
     200                 :            :             case WINDOW_METRICFIELD:
     201                 :            :             case WINDOW_CURRENCYFIELD:
     202                 :            :             case WINDOW_DATEFIELD:
     203                 :            :             case WINDOW_TIMEFIELD:
     204                 :            :             case WINDOW_LONGCURRENCYFIELD:
     205                 :            :             case WINDOW_NUMERICFIELD:
     206                 :            :             case WINDOW_SPINFIELD:
     207                 :        702 :                 aControl = CTRL_SPINBOX;
     208                 :        702 :                 break;
     209                 :            :             default:
     210                 :          5 :                 aControl = CTRL_SPINBUTTONS;
     211                 :          5 :                 break;
     212                 :            :         }
     213                 :            : 
     214         [ +  - ]:        707 :         SpinbuttonValue aValue;
     215                 :            :         ImplGetSpinbuttonValue( pWin, rUpperRect, rLowerRect,
     216                 :            :                                 bUpperIn, bLowerIn, bUpperEnabled, bLowerEnabled,
     217         [ +  - ]:        707 :                                 bHorz, aValue );
     218                 :            : 
     219         [ +  + ]:        707 :         if( aControl == CTRL_SPINBOX )
     220         [ +  - ]:        702 :             bNativeOK = ImplDrawNativeSpinfield( pWin, aValue );
     221         [ +  - ]:          5 :         else if( aControl == CTRL_SPINBUTTONS )
     222 [ +  - ][ +  - ]:        707 :             bNativeOK = ImplDrawNativeSpinbuttons( pWin, aValue );
     223                 :            :     }
     224                 :            : 
     225         [ +  - ]:        707 :     if( !bNativeOK )
     226         [ +  - ]:        707 :         aUpRect = aDecoView.DrawButton( rUpperRect, nTempStyle );
     227                 :            : 
     228                 :            :     // Unteren/rechten Button malen
     229         [ -  + ]:        707 :     if ( bLowerIn )
     230                 :          0 :         nStyle |= BUTTON_DRAW_PRESSED;
     231         [ +  - ]:        707 :     Rectangle aLowRect;
     232         [ +  - ]:        707 :     if( !bNativeOK )
     233         [ +  - ]:        707 :         aLowRect = aDecoView.DrawButton( rLowerRect, nStyle );
     234                 :            : 
     235                 :            :     // Zusaetzliche Default-Kante wollen wir auch ausnutzen
     236                 :        707 :     aUpRect.Left()--;
     237                 :        707 :     aUpRect.Top()--;
     238                 :        707 :     aUpRect.Right()++;
     239                 :        707 :     aUpRect.Bottom()++;
     240                 :        707 :     aLowRect.Left()--;
     241                 :        707 :     aLowRect.Top()--;
     242                 :        707 :     aLowRect.Right()++;
     243                 :        707 :     aLowRect.Bottom()++;
     244                 :            : 
     245                 :            :     // Wir malen auch in die Kante rein, damit man etwas erkennen kann,
     246                 :            :     // wenn das Rechteck zu klein ist
     247 [ +  + ][ +  - ]:        707 :     if ( aUpRect.GetHeight() < 4 )
     248                 :            :     {
     249                 :        285 :         aUpRect.Right()++;
     250                 :        285 :         aUpRect.Bottom()++;
     251                 :        285 :         aLowRect.Right()++;
     252                 :        285 :         aLowRect.Bottom()++;
     253                 :            :     }
     254                 :            : 
     255                 :            :     // Symbolgroesse berechnen
     256         [ +  - ]:        707 :     long nTempSize1 = aUpRect.GetWidth();
     257         [ +  - ]:        707 :     long nTempSize2 = aLowRect.GetWidth();
     258         [ +  + ]:        707 :     if ( Abs( nTempSize1-nTempSize2 ) == 1 )
     259                 :            :     {
     260         [ -  + ]:          2 :         if ( nTempSize1 > nTempSize2 )
     261                 :          0 :             aUpRect.Left()++;
     262                 :            :         else
     263                 :          2 :             aLowRect.Left()++;
     264                 :            :     }
     265         [ +  - ]:        707 :     nTempSize1 = aUpRect.GetHeight();
     266         [ +  - ]:        707 :     nTempSize2 = aLowRect.GetHeight();
     267         [ -  + ]:        707 :     if ( Abs( nTempSize1-nTempSize2 ) == 1 )
     268                 :            :     {
     269         [ #  # ]:          0 :         if ( nTempSize1 > nTempSize2 )
     270                 :          0 :             aUpRect.Top()++;
     271                 :            :         else
     272                 :          0 :             aLowRect.Top()++;
     273                 :            :     }
     274                 :            : 
     275                 :        707 :     nTempStyle = nSymStyle;
     276         [ +  + ]:        707 :     if ( !bUpperEnabled )
     277                 :        247 :         nTempStyle |= SYMBOL_DRAW_DISABLE;
     278         [ +  - ]:        707 :     if( !bNativeOK )
     279         [ +  - ]:        707 :         aDecoView.DrawSymbol( aUpRect, eType1, rStyleSettings.GetButtonTextColor(), nTempStyle );
     280                 :            : 
     281         [ +  + ]:        707 :     if ( !bLowerEnabled )
     282                 :        252 :         nSymStyle |= SYMBOL_DRAW_DISABLE;
     283         [ +  - ]:        707 :     if( !bNativeOK )
     284         [ +  - ]:        707 :         aDecoView.DrawSymbol( aLowRect, eType2, rStyleSettings.GetButtonTextColor(), nSymStyle );
     285                 :        707 : }
     286                 :            : 
     287                 :            : // =======================================================================
     288                 :            : 
     289                 :        435 : void SpinField::ImplInitSpinFieldData()
     290                 :            : {
     291                 :        435 :     mpEdit          = NULL;
     292                 :        435 :     mbSpin          = sal_False;
     293                 :        435 :     mbRepeat        = sal_False;
     294                 :        435 :     mbUpperIn       = sal_False;
     295                 :        435 :     mbLowerIn       = sal_False;
     296                 :        435 :     mbInitialUp     = sal_False;
     297                 :        435 :     mbInitialDown   = sal_False;
     298                 :        435 :     mbNoSelect      = sal_False;
     299                 :        435 :     mbInDropDown    = sal_False;
     300                 :        435 : }
     301                 :            : 
     302                 :            : // --------------------------------------------------------------------
     303                 :            : 
     304                 :        435 : void SpinField::ImplInit( Window* pParent, WinBits nWinStyle )
     305                 :            : {
     306                 :        435 :     Edit::ImplInit( pParent, nWinStyle );
     307                 :            : 
     308         [ +  + ]:        435 :     if ( nWinStyle & (WB_SPIN|WB_DROPDOWN) )
     309                 :            :     {
     310                 :        187 :         mbSpin = sal_True;
     311                 :            : 
     312                 :            :         // Some themes want external spin buttons, therefore the main
     313                 :            :         // spinfield should not overdraw the border between its encapsulated
     314                 :            :         // edit field and the spin buttons
     315 [ +  + ][ -  + ]:        187 :         if ( (nWinStyle & WB_SPIN) && ImplUseNativeBorder( nWinStyle ) )
                 [ -  + ]
     316                 :            :         {
     317                 :          0 :             SetBackground();
     318         [ #  # ]:          0 :             mpEdit = new Edit( this, WB_NOBORDER );
     319                 :          0 :             mpEdit->SetBackground();
     320                 :            :         }
     321                 :            :         else
     322         [ +  - ]:        187 :             mpEdit = new Edit( this, WB_NOBORDER );
     323                 :            : 
     324                 :        187 :         mpEdit->EnableRTL( sal_False );
     325         [ +  - ]:        187 :         mpEdit->SetPosPixel( Point() );
     326                 :        187 :         mpEdit->Show();
     327                 :        187 :         SetSubEdit( mpEdit );
     328                 :            : 
     329                 :        187 :         maRepeatTimer.SetTimeoutHdl( LINK( this, SpinField, ImplTimeout ) );
     330                 :        187 :         maRepeatTimer.SetTimeout( GetSettings().GetMouseSettings().GetButtonStartRepeat() );
     331         [ +  + ]:        187 :         if ( nWinStyle & WB_REPEAT )
     332                 :        129 :             mbRepeat = sal_True;
     333                 :            : 
     334                 :        187 :         SetCompoundControl( sal_True );
     335                 :            :     }
     336                 :        435 : }
     337                 :            : 
     338                 :            : // --------------------------------------------------------------------
     339                 :            : 
     340                 :          0 : SpinField::SpinField( WindowType nTyp ) :
     341 [ #  # ][ #  # ]:          0 :     Edit( nTyp )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     342                 :            : {
     343                 :          0 :     ImplInitSpinFieldData();
     344                 :          0 : }
     345                 :            : 
     346                 :            : // --------------------------------------------------------------------
     347                 :            : 
     348                 :        435 : SpinField::SpinField( Window* pParent, WinBits nWinStyle ) :
     349 [ +  - ][ +  - ]:        435 :     Edit( WINDOW_SPINFIELD )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     350                 :            : {
     351                 :        435 :     ImplInitSpinFieldData();
     352         [ +  - ]:        435 :     ImplInit( pParent, nWinStyle );
     353                 :        435 : }
     354                 :            : 
     355                 :            : // --------------------------------------------------------------------
     356                 :            : 
     357                 :          0 : SpinField::SpinField( Window* pParent, const ResId& rResId ) :
     358 [ #  # ][ #  # ]:          0 :     Edit( WINDOW_SPINFIELD )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     359                 :            : {
     360                 :          0 :     ImplInitSpinFieldData();
     361                 :          0 :     rResId.SetRT( RSC_SPINFIELD );
     362         [ #  # ]:          0 :     WinBits nStyle = ImplInitRes( rResId );
     363         [ #  # ]:          0 :     ImplInit( pParent, nStyle );
     364         [ #  # ]:          0 :     ImplLoadRes( rResId );
     365                 :            : 
     366         [ #  # ]:          0 :     if ( !(nStyle & WB_HIDE) )
     367         [ #  # ]:          0 :         Show();
     368                 :          0 : }
     369                 :            : 
     370                 :            : // --------------------------------------------------------------------
     371                 :            : 
     372         [ +  - ]:        435 : SpinField::~SpinField()
     373                 :            : {
     374 [ +  + ][ +  - ]:        435 :     delete mpEdit;
     375         [ -  + ]:        435 : }
     376                 :            : 
     377                 :            : // --------------------------------------------------------------------
     378                 :            : 
     379                 :         44 : void SpinField::Up()
     380                 :            : {
     381                 :         44 :     ImplCallEventListenersAndHandler( VCLEVENT_SPINFIELD_UP, maUpHdlLink, this );
     382                 :         44 : }
     383                 :            : 
     384                 :            : // --------------------------------------------------------------------
     385                 :            : 
     386                 :         22 : void SpinField::Down()
     387                 :            : {
     388                 :         22 :     ImplCallEventListenersAndHandler( VCLEVENT_SPINFIELD_DOWN, maDownHdlLink, this );
     389                 :         22 : }
     390                 :            : 
     391                 :            : // --------------------------------------------------------------------
     392                 :            : 
     393                 :         22 : void SpinField::First()
     394                 :            : {
     395                 :         22 :     ImplCallEventListenersAndHandler( VCLEVENT_SPINFIELD_FIRST, maFirstHdlLink, this );
     396                 :         22 : }
     397                 :            : 
     398                 :            : // --------------------------------------------------------------------
     399                 :            : 
     400                 :         22 : void SpinField::Last()
     401                 :            : {
     402                 :         22 :     ImplCallEventListenersAndHandler( VCLEVENT_SPINFIELD_LAST, maLastHdlLink, this );
     403                 :         22 : }
     404                 :            : 
     405                 :            : // --------------------------------------------------------------------
     406                 :            : 
     407                 :          0 : void SpinField::MouseButtonDown( const MouseEvent& rMEvt )
     408                 :            : {
     409 [ #  # ][ #  # ]:          0 :     if ( !HasFocus() && ( !mpEdit || !mpEdit->HasFocus() ) )
         [ #  # ][ #  # ]
     410                 :            :     {
     411                 :          0 :         mbNoSelect = sal_True;
     412                 :          0 :         GrabFocus();
     413                 :            :     }
     414                 :            : 
     415         [ #  # ]:          0 :     if ( !IsReadOnly() )
     416                 :            :     {
     417         [ #  # ]:          0 :         if ( maUpperRect.IsInside( rMEvt.GetPosPixel() ) )
     418                 :            :         {
     419                 :          0 :             mbUpperIn   = sal_True;
     420                 :          0 :             mbInitialUp = sal_True;
     421                 :          0 :             Invalidate( maUpperRect );
     422                 :            :         }
     423         [ #  # ]:          0 :         else if ( maLowerRect.IsInside( rMEvt.GetPosPixel() ) )
     424                 :            :         {
     425                 :          0 :             mbLowerIn    = sal_True;
     426                 :          0 :             mbInitialDown = sal_True;
     427                 :          0 :             Invalidate( maLowerRect );
     428                 :            :         }
     429         [ #  # ]:          0 :         else if ( maDropDownRect.IsInside( rMEvt.GetPosPixel() ) )
     430                 :            :         {
     431                 :            :             // Rechts daneben liegt der DropDownButton:
     432                 :          0 :             mbInDropDown = ShowDropDown( mbInDropDown ? sal_False : sal_True );
     433 [ #  # ][ #  # ]:          0 :             Paint( Rectangle( Point(), GetOutputSizePixel() ) );
     434                 :            :         }
     435                 :            : 
     436 [ #  # ][ #  # ]:          0 :         if ( mbUpperIn || mbLowerIn )
     437                 :            :         {
     438                 :          0 :             Update();
     439                 :          0 :             CaptureMouse();
     440         [ #  # ]:          0 :             if ( mbRepeat )
     441                 :          0 :                 maRepeatTimer.Start();
     442                 :          0 :             return;
     443                 :            :         }
     444                 :            :     }
     445                 :            : 
     446                 :          0 :     Edit::MouseButtonDown( rMEvt );
     447                 :            : }
     448                 :            : 
     449                 :            : // --------------------------------------------------------------------
     450                 :            : 
     451                 :          0 : void SpinField::MouseButtonUp( const MouseEvent& rMEvt )
     452                 :            : {
     453                 :          0 :     ReleaseMouse();
     454                 :          0 :     mbInitialUp = mbInitialDown = sal_False;
     455                 :          0 :     maRepeatTimer.Stop();
     456                 :          0 :     maRepeatTimer.SetTimeout( GetSettings().GetMouseSettings().GetButtonStartRepeat() );
     457                 :            : 
     458         [ #  # ]:          0 :     if ( mbUpperIn )
     459                 :            :     {
     460                 :          0 :         mbUpperIn = sal_False;
     461                 :          0 :         Invalidate( maUpperRect );
     462                 :          0 :         Update();
     463                 :          0 :         Up();
     464                 :            :     }
     465         [ #  # ]:          0 :     else if ( mbLowerIn )
     466                 :            :     {
     467                 :          0 :         mbLowerIn = sal_False;
     468                 :          0 :         Invalidate( maLowerRect );
     469                 :          0 :         Update();
     470                 :          0 :         Down();
     471                 :            :     }
     472                 :            : 
     473                 :          0 :     Edit::MouseButtonUp( rMEvt );
     474                 :          0 : }
     475                 :            : 
     476                 :            : // --------------------------------------------------------------------
     477                 :            : 
     478                 :          0 : void SpinField::MouseMove( const MouseEvent& rMEvt )
     479                 :            : {
     480         [ #  # ]:          0 :     if ( rMEvt.IsLeft() )
     481                 :            :     {
     482         [ #  # ]:          0 :         if ( mbInitialUp )
     483                 :            :         {
     484                 :          0 :             sal_Bool bNewUpperIn = maUpperRect.IsInside( rMEvt.GetPosPixel() );
     485         [ #  # ]:          0 :             if ( bNewUpperIn != mbUpperIn )
     486                 :            :             {
     487         [ #  # ]:          0 :                 if ( bNewUpperIn )
     488                 :            :                 {
     489         [ #  # ]:          0 :                     if ( mbRepeat )
     490                 :          0 :                         maRepeatTimer.Start();
     491                 :            :                 }
     492                 :            :                 else
     493                 :          0 :                     maRepeatTimer.Stop();
     494                 :            : 
     495                 :          0 :                 mbUpperIn = bNewUpperIn;
     496                 :          0 :                 Invalidate( maUpperRect );
     497                 :          0 :                 Update();
     498                 :            :             }
     499                 :            :         }
     500         [ #  # ]:          0 :         else if ( mbInitialDown )
     501                 :            :         {
     502                 :          0 :             sal_Bool bNewLowerIn = maLowerRect.IsInside( rMEvt.GetPosPixel() );
     503         [ #  # ]:          0 :             if ( bNewLowerIn != mbLowerIn )
     504                 :            :             {
     505         [ #  # ]:          0 :                 if ( bNewLowerIn )
     506                 :            :                 {
     507         [ #  # ]:          0 :                     if ( mbRepeat )
     508                 :          0 :                         maRepeatTimer.Start();
     509                 :            :                 }
     510                 :            :                 else
     511                 :          0 :                     maRepeatTimer.Stop();
     512                 :            : 
     513                 :          0 :                 mbLowerIn = bNewLowerIn;
     514                 :          0 :                 Invalidate( maLowerRect );
     515                 :          0 :                 Update();
     516                 :            :             }
     517                 :            :         }
     518                 :            :     }
     519                 :            : 
     520                 :          0 :     Edit::MouseMove( rMEvt );
     521                 :          0 : }
     522                 :            : 
     523                 :            : // --------------------------------------------------------------------
     524                 :            : 
     525                 :        387 : long SpinField::Notify( NotifyEvent& rNEvt )
     526                 :            : {
     527                 :        387 :     long nDone = 0;
     528         [ -  + ]:        387 :     if( rNEvt.GetType() == EVENT_KEYINPUT )
     529                 :            :     {
     530                 :          0 :         const KeyEvent& rKEvt = *rNEvt.GetKeyEvent();
     531         [ #  # ]:          0 :         if ( !IsReadOnly() )
     532                 :            :         {
     533                 :          0 :             sal_uInt16 nMod = rKEvt.GetKeyCode().GetModifier();
     534   [ #  #  #  #  :          0 :             switch ( rKEvt.GetKeyCode().GetCode() )
                      # ]
     535                 :            :             {
     536                 :            :                 case KEY_UP:
     537                 :            :                 {
     538         [ #  # ]:          0 :                     if ( !nMod )
     539                 :            :                     {
     540                 :          0 :                         Up();
     541                 :          0 :                         nDone = 1;
     542                 :            :                     }
     543                 :            :                 }
     544                 :          0 :                 break;
     545                 :            :                 case KEY_DOWN:
     546                 :            :                 {
     547         [ #  # ]:          0 :                     if ( !nMod )
     548                 :            :                     {
     549                 :          0 :                         Down();
     550                 :          0 :                         nDone = 1;
     551                 :            :                     }
     552 [ #  # ][ #  # ]:          0 :                     else if ( ( nMod == KEY_MOD2 ) && !mbInDropDown && ( GetStyle() & WB_DROPDOWN ) )
         [ #  # ][ #  # ]
     553                 :            :                     {
     554                 :          0 :                         mbInDropDown = ShowDropDown( sal_True );
     555 [ #  # ][ #  # ]:          0 :                         Paint( Rectangle( Point(), GetOutputSizePixel() ) );
     556                 :          0 :                         nDone = 1;
     557                 :            :                     }
     558                 :            :                 }
     559                 :          0 :                 break;
     560                 :            :                 case KEY_PAGEUP:
     561                 :            :                 {
     562         [ #  # ]:          0 :                     if ( !nMod )
     563                 :            :                     {
     564                 :          0 :                         Last();
     565                 :          0 :                         nDone = 1;
     566                 :            :                     }
     567                 :            :                 }
     568                 :          0 :                 break;
     569                 :            :                 case KEY_PAGEDOWN:
     570                 :            :                 {
     571         [ #  # ]:          0 :                     if ( !nMod )
     572                 :            :                     {
     573                 :          0 :                         First();
     574                 :          0 :                         nDone = 1;
     575                 :            :                     }
     576                 :            :                 }
     577                 :          0 :                 break;
     578                 :            :             }
     579                 :            :         }
     580                 :            :     }
     581                 :            : 
     582         [ -  + ]:        387 :     if ( rNEvt.GetType() == EVENT_COMMAND )
     583                 :            :     {
     584 [ #  # ][ #  # ]:          0 :         if ( ( rNEvt.GetCommandEvent()->GetCommand() == COMMAND_WHEEL ) && !IsReadOnly() )
                 [ #  # ]
     585                 :            :         {
     586                 :          0 :             sal_uInt16 nWheelBehavior( GetSettings().GetMouseSettings().GetWheelBehavior() );
     587   [ #  #  #  # ]:          0 :             if  (   ( nWheelBehavior == MOUSE_WHEEL_ALWAYS )
         [ #  # ][ #  # ]
     588                 :            :                 ||  (   ( nWheelBehavior == MOUSE_WHEEL_FOCUS_ONLY )
     589                 :          0 :                     &&  HasChildPathFocus()
     590                 :            :                     )
     591                 :            :                 )
     592                 :            :             {
     593                 :          0 :                 const CommandWheelData* pData = rNEvt.GetCommandEvent()->GetWheelData();
     594         [ #  # ]:          0 :                 if ( pData->GetMode() == COMMAND_WHEEL_SCROLL )
     595                 :            :                 {
     596         [ #  # ]:          0 :                     if ( pData->GetDelta() < 0L )
     597                 :          0 :                         Down();
     598                 :            :                     else
     599                 :          0 :                         Up();
     600                 :          0 :                     nDone = 1;
     601                 :            :                 }
     602                 :            :             }
     603                 :            :             else
     604                 :          0 :                 nDone = 0;  // don't eat this event, let the default handling happen (i.e. scroll the context)
     605                 :            :         }
     606                 :            :     }
     607                 :            : 
     608         [ +  - ]:        387 :     return nDone ? nDone : Edit::Notify( rNEvt );
     609                 :            : }
     610                 :            : 
     611                 :            : // --------------------------------------------------------------------
     612                 :            : 
     613                 :          0 : void SpinField::Command( const CommandEvent& rCEvt )
     614                 :            : {
     615                 :          0 :     Edit::Command( rCEvt );
     616                 :          0 : }
     617                 :            : 
     618                 :            : // --------------------------------------------------------------------
     619                 :            : 
     620                 :          0 : void SpinField::FillLayoutData() const
     621                 :            : {
     622         [ #  # ]:          0 :     if( mbSpin )
     623                 :            :     {
     624         [ #  # ]:          0 :         mpControlData->mpLayoutData = new vcl::ControlLayoutData();
     625                 :          0 :         AppendLayoutData( *GetSubEdit() );
     626                 :          0 :         GetSubEdit()->SetLayoutDataParent( this );
     627                 :            :     }
     628                 :            :     else
     629                 :          0 :         Edit::FillLayoutData();
     630                 :          0 : }
     631                 :            : 
     632                 :            : // --------------------------------------------------------------------
     633                 :            : 
     634                 :       1910 : void SpinField::Paint( const Rectangle& rRect )
     635                 :            : {
     636         [ +  + ]:       1910 :     if ( mbSpin )
     637                 :            :     {
     638                 :        702 :         sal_Bool    bEnable = IsEnabled();
     639                 :            :         ImplDrawSpinButton( this, maUpperRect, maLowerRect,
     640                 :        702 :                             mbUpperIn, mbLowerIn, bEnable, bEnable );
     641                 :            :     }
     642                 :            : 
     643         [ +  + ]:       1910 :     if ( GetStyle() & WB_DROPDOWN )
     644                 :            :     {
     645                 :        137 :         DecorationView aView( this );
     646                 :            : 
     647                 :        137 :         sal_uInt16 nStyle = BUTTON_DRAW_NOLIGHTBORDER;
     648         [ -  + ]:        137 :         if ( mbInDropDown )
     649                 :          0 :             nStyle |= BUTTON_DRAW_PRESSED;
     650         [ +  - ]:        137 :         Rectangle aInnerRect = aView.DrawButton( maDropDownRect, nStyle );
     651                 :            : 
     652                 :        137 :         SymbolType eSymbol = SYMBOL_SPIN_DOWN;
     653         [ -  + ]:        137 :         if ( GetSettings().GetStyleSettings().GetOptions() & STYLE_OPTION_SPINUPDOWN )
     654                 :          0 :             eSymbol = SYMBOL_SPIN_UPDOWN;
     655                 :            : 
     656 [ +  - ][ +  + ]:        137 :         nStyle = IsEnabled() ? 0 : SYMBOL_DRAW_DISABLE;
     657         [ +  - ]:        137 :         aView.DrawSymbol( aInnerRect, eSymbol, GetSettings().GetStyleSettings().GetButtonTextColor(), nStyle );
     658                 :            :     }
     659                 :            : 
     660                 :       1910 :     Edit::Paint( rRect );
     661                 :       1910 : }
     662                 :            : 
     663                 :            : // --------------------------------------------------------------------
     664                 :            : 
     665                 :       1065 : void SpinField::ImplCalcButtonAreas( OutputDevice* pDev, const Size& rOutSz, Rectangle& rDDArea, Rectangle& rSpinUpArea, Rectangle& rSpinDownArea )
     666                 :            : {
     667                 :       1065 :     const StyleSettings& rStyleSettings = pDev->GetSettings().GetStyleSettings();
     668                 :            : 
     669                 :       1065 :     Size aSize = rOutSz;
     670                 :       1065 :     Size aDropDownSize;
     671                 :            : 
     672 [ +  + ][ +  - ]:       1065 :     if ( GetStyle() & WB_DROPDOWN )
     673                 :            :     {
     674                 :        256 :         long nW = rStyleSettings.GetScrollBarSize();
     675         [ +  - ]:        256 :         nW = GetDrawPixel( pDev, nW );
     676         [ +  - ]:        256 :         aDropDownSize = Size( CalcZoom( nW ), aSize.Height() );
     677                 :        256 :         aSize.Width() -= aDropDownSize.Width();
     678         [ +  - ]:        256 :         rDDArea = Rectangle( Point( aSize.Width(), 0 ), aDropDownSize );
     679                 :        256 :         rDDArea.Top()--;
     680                 :            :     }
     681                 :            :     else
     682                 :        809 :         rDDArea.SetEmpty();
     683                 :            : 
     684                 :            :     // Je nach Hoehe, die groessen Berechnen
     685 [ +  - ][ +  + ]:       1065 :     if ( GetStyle() & WB_SPIN )
     686                 :            :     {
     687                 :        893 :         long nBottom1 = aSize.Height()/2;
     688                 :        893 :         long nBottom2 = aSize.Height()-1;
     689                 :        893 :         long nTop2 = nBottom1;
     690                 :        893 :         long nTop1 = 0;
     691         [ -  + ]:        893 :         if ( !(aSize.Height() & 0x01) )
     692                 :          0 :             nBottom1--;
     693                 :            : 
     694                 :        893 :         sal_Bool bNativeRegionOK = sal_False;
     695 [ +  - ][ +  - ]:        893 :         Rectangle aContentUp, aContentDown;
     696                 :            : 
     697 [ +  - ][ +  + ]:       2595 :         if ( (pDev->GetOutDevType() == OUTDEV_WINDOW) &&
         [ -  + ][ -  + ]
     698                 :            :             // there is just no useful native support for spinfields with dropdown
     699         [ +  - ]:        893 :             ! (GetStyle() & WB_DROPDOWN) &&
     700         [ +  - ]:        809 :             IsNativeControlSupported(CTRL_SPINBOX, PART_ENTIRE_CONTROL) )
     701                 :            :         {
     702                 :          0 :             Window *pWin = (Window*) pDev;
     703         [ #  # ]:          0 :             Window *pBorder = pWin->GetWindow( WINDOW_BORDER );
     704                 :            : 
     705                 :            :             // get the system's spin button size
     706                 :          0 :             ImplControlValue aControlValue;
     707         [ #  # ]:          0 :             Rectangle aBound;
     708                 :          0 :             Point aPoint;
     709                 :            : 
     710                 :            :             // use the full extent of the control
     711         [ #  # ]:          0 :             Rectangle aArea( aPoint, pBorder->GetOutputSizePixel() );
     712                 :            : 
     713                 :            :             bNativeRegionOK =
     714                 :            :                 pWin->GetNativeControlRegion(CTRL_SPINBOX, PART_BUTTON_UP,
     715 [ #  # ][ #  # ]:          0 :                     aArea, 0, aControlValue, rtl::OUString(), aBound, aContentUp) &&
                 [ #  # ]
     716                 :            :                 pWin->GetNativeControlRegion(CTRL_SPINBOX, PART_BUTTON_DOWN,
     717 [ #  # ][ #  # ]:          0 :                     aArea, 0, aControlValue, rtl::OUString(), aBound, aContentDown);
         [ #  # ][ #  # ]
                 [ #  # ]
     718                 :            : 
     719         [ #  # ]:          0 :             if( bNativeRegionOK )
     720                 :            :             {
     721                 :            :                 // convert back from border space to local coordinates
     722 [ #  # ][ #  # ]:          0 :                 aPoint = pBorder->ScreenToOutputPixel( pWin->OutputToScreenPixel( aPoint ) );
     723         [ #  # ]:          0 :                 aContentUp.Move(-aPoint.X(), -aPoint.Y());
     724         [ #  # ]:          0 :                 aContentDown.Move(-aPoint.X(), -aPoint.Y());
     725         [ #  # ]:          0 :             }
     726                 :            :         }
     727                 :            : 
     728         [ -  + ]:        893 :         if( bNativeRegionOK )
     729                 :            :         {
     730                 :          0 :             rSpinUpArea = aContentUp;
     731                 :          0 :             rSpinDownArea = aContentDown;
     732                 :            :         }
     733                 :            :         else
     734                 :            :         {
     735 [ +  - ][ +  - ]:        893 :             aSize.Width() -= CalcZoom( GetDrawPixel( pDev, rStyleSettings.GetSpinSize() ) );
     736                 :            : 
     737         [ +  - ]:        893 :             rSpinUpArea = Rectangle( aSize.Width(), nTop1, rOutSz.Width()-aDropDownSize.Width()-1, nBottom1 );
     738         [ +  - ]:        893 :             rSpinDownArea = Rectangle( rSpinUpArea.Left(), nTop2, rSpinUpArea.Right(), nBottom2 );
     739                 :            :         }
     740                 :            :     }
     741                 :            :     else
     742                 :            :     {
     743                 :        172 :         rSpinUpArea.SetEmpty();
     744                 :        172 :         rSpinDownArea.SetEmpty();
     745                 :            :     }
     746                 :       1065 : }
     747                 :            : 
     748                 :            : // --------------------------------------------------------------------
     749                 :            : 
     750                 :       2877 : void SpinField::Resize()
     751                 :            : {
     752         [ +  + ]:       2877 :     if ( mbSpin )
     753                 :            :     {
     754         [ +  - ]:       1065 :         Control::Resize();
     755                 :       1065 :         Size aSize = GetOutputSizePixel();
     756                 :       1065 :         bool bSubEditPositioned = false;
     757                 :            : 
     758 [ +  - ][ +  - ]:       1065 :         if ( GetStyle() & (WB_SPIN|WB_DROPDOWN) )
     759                 :            :         {
     760         [ +  - ]:       1065 :             ImplCalcButtonAreas( this, aSize, maDropDownRect, maUpperRect, maLowerRect );
     761                 :            : 
     762                 :       1065 :             ImplControlValue aControlValue;
     763                 :       1065 :             Point aPoint;
     764 [ +  - ][ +  - ]:       1065 :             Rectangle aContent, aBound;
     765                 :            : 
     766                 :            :             // use the full extent of the control
     767         [ +  - ]:       1065 :             Window *pBorder = GetWindow( WINDOW_BORDER );
     768         [ +  - ]:       1065 :             Rectangle aArea( aPoint, pBorder->GetOutputSizePixel() );
     769                 :            : 
     770                 :            :             // adjust position and size of the edit field
     771         [ -  + ]:       1065 :             if ( GetNativeControlRegion(CTRL_SPINBOX, PART_SUB_EDIT,
     772         [ +  - ]:       1065 :                         aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
     773                 :            :             {
     774                 :            :                 // convert back from border space to local coordinates
     775 [ #  # ][ #  # ]:          0 :                 aPoint = pBorder->ScreenToOutputPixel( OutputToScreenPixel( aPoint ) );
     776         [ #  # ]:          0 :                 aContent.Move(-aPoint.X(), -aPoint.Y());
     777                 :            : 
     778                 :            :                 // use the themes drop down size
     779         [ #  # ]:          0 :                 mpEdit->SetPosPixel( aContent.TopLeft() );
     780                 :          0 :                 bSubEditPositioned = true;
     781         [ #  # ]:          0 :                 aSize = aContent.GetSize();
     782                 :            :             }
     783                 :            :             else
     784                 :            :             {
     785 [ +  - ][ +  + ]:       1065 :                 if ( maUpperRect.IsEmpty() )
     786                 :            :                 {
     787                 :            :                     DBG_ASSERT( !maDropDownRect.IsEmpty(), "SpinField::Resize: SPIN && DROPDOWN, but all empty rects?" );
     788                 :        172 :                     aSize.Width() = maDropDownRect.Left();
     789                 :            :                 }
     790                 :            :                 else
     791                 :        893 :                     aSize.Width() = maUpperRect.Left();
     792         [ +  - ]:       1065 :             }
     793                 :            :         }
     794                 :            : 
     795         [ +  - ]:       1065 :         if( ! bSubEditPositioned )
     796                 :            :         {
     797                 :            :             // this moves our sub edit if RTL gets switched
     798         [ +  - ]:       1065 :             mpEdit->SetPosPixel( Point() );
     799                 :            :         }
     800         [ +  - ]:       1065 :         mpEdit->SetSizePixel( aSize );
     801                 :            : 
     802 [ +  - ][ +  + ]:       1065 :         if ( GetStyle() & WB_SPIN )
     803 [ +  - ][ +  - ]:        893 :             Invalidate( Rectangle( maUpperRect.TopLeft(), maLowerRect.BottomRight() ) );
                 [ +  - ]
     804 [ +  - ][ +  + ]:       1065 :         if ( GetStyle() & WB_DROPDOWN )
     805         [ +  - ]:       1065 :             Invalidate( maDropDownRect );
     806                 :            :     }
     807                 :       2877 : }
     808                 :            : 
     809                 :            : // -----------------------------------------------------------------------
     810                 :            : 
     811                 :       6892 : void SpinField::StateChanged( StateChangedType nType )
     812                 :            : {
     813                 :       6892 :     Edit::StateChanged( nType );
     814                 :            : 
     815         [ +  + ]:       6892 :     if ( nType == STATE_CHANGE_ENABLE )
     816                 :            :     {
     817 [ +  + ][ -  + ]:        320 :         if ( mbSpin || ( GetStyle() & WB_DROPDOWN ) )
                 [ +  + ]
     818                 :            :         {
     819                 :        100 :             mpEdit->Enable( IsEnabled() );
     820                 :            : 
     821         [ +  - ]:        100 :             if ( mbSpin )
     822                 :            :             {
     823                 :        100 :                 Invalidate( maLowerRect );
     824                 :        100 :                 Invalidate( maUpperRect );
     825                 :            :             }
     826         [ +  + ]:        100 :             if ( GetStyle() & WB_DROPDOWN )
     827                 :         20 :                 Invalidate( maDropDownRect );
     828                 :            :         }
     829                 :            :     }
     830         [ +  + ]:       6572 :     else if ( nType == STATE_CHANGE_STYLE )
     831                 :            :     {
     832         [ +  + ]:        658 :         if ( GetStyle() & WB_REPEAT )
     833                 :        202 :             mbRepeat = sal_True;
     834                 :            :         else
     835                 :        456 :             mbRepeat = sal_False;
     836                 :            :     }
     837         [ -  + ]:       5914 :     else if ( nType == STATE_CHANGE_ZOOM )
     838                 :            :     {
     839                 :          0 :         Resize();
     840         [ #  # ]:          0 :         if ( mpEdit )
     841                 :          0 :             mpEdit->SetZoom( GetZoom() );
     842                 :          0 :         Invalidate();
     843                 :            :     }
     844         [ +  + ]:       5914 :     else if ( nType == STATE_CHANGE_CONTROLFONT )
     845                 :            :     {
     846         [ +  + ]:       1249 :         if ( mpEdit )
     847         [ +  - ]:        530 :             mpEdit->SetControlFont( GetControlFont() );
     848                 :       1249 :         ImplInitSettings( sal_True, sal_False, sal_False );
     849                 :       1249 :         Invalidate();
     850                 :            :     }
     851         [ -  + ]:       4665 :     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
     852                 :            :     {
     853         [ #  # ]:          0 :         if ( mpEdit )
     854         [ #  # ]:          0 :             mpEdit->SetControlForeground( GetControlForeground() );
     855                 :          0 :         ImplInitSettings( sal_False, sal_True, sal_False );
     856                 :          0 :         Invalidate();
     857                 :            :     }
     858         [ -  + ]:       4665 :     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
     859                 :            :     {
     860         [ #  # ]:          0 :         if ( mpEdit )
     861         [ #  # ]:          0 :             mpEdit->SetControlBackground( GetControlBackground() );
     862                 :          0 :         ImplInitSettings( sal_False, sal_False, sal_True );
     863                 :          0 :         Invalidate();
     864                 :            :     }
     865         [ +  + ]:       4665 :     else if( nType == STATE_CHANGE_MIRRORING )
     866                 :            :     {
     867         [ +  + ]:        728 :         if( mpEdit )
     868                 :        152 :             mpEdit->StateChanged( STATE_CHANGE_MIRRORING );
     869                 :        728 :         Resize();
     870                 :            :     }
     871                 :       6892 : }
     872                 :            : 
     873                 :            : // -----------------------------------------------------------------------
     874                 :            : 
     875                 :       2280 : void SpinField::DataChanged( const DataChangedEvent& rDCEvt )
     876                 :            : {
     877                 :       2280 :     Edit::DataChanged( rDCEvt );
     878                 :            : 
     879         [ +  + ]:       4560 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
           [ +  -  +  + ]
     880                 :       2280 :          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
     881                 :            :     {
     882                 :       1748 :         Resize();
     883                 :       1748 :         Invalidate();
     884                 :            :     }
     885                 :       2280 : }
     886                 :            : 
     887                 :            : // -----------------------------------------------------------------------
     888                 :            : 
     889                 :          0 : Rectangle* SpinField::ImplFindPartRect( const Point& rPt )
     890                 :            : {
     891         [ #  # ]:          0 :     if( maUpperRect.IsInside( rPt ) )
     892                 :          0 :         return &maUpperRect;
     893         [ #  # ]:          0 :     else if( maLowerRect.IsInside( rPt ) )
     894                 :          0 :         return &maLowerRect;
     895                 :            :     else
     896                 :          0 :         return NULL;
     897                 :            : }
     898                 :            : 
     899                 :          0 : long SpinField::PreNotify( NotifyEvent& rNEvt )
     900                 :            : {
     901                 :          0 :     long nDone = 0;
     902                 :          0 :     const MouseEvent* pMouseEvt = NULL;
     903                 :            : 
     904 [ #  # ][ #  # ]:          0 :     if( (rNEvt.GetType() == EVENT_MOUSEMOVE) && (pMouseEvt = rNEvt.GetMouseEvent()) != NULL )
                 [ #  # ]
     905                 :            :     {
     906 [ #  # ][ #  # ]:          0 :         if( !pMouseEvt->GetButtons() && !pMouseEvt->IsSynthetic() && !pMouseEvt->IsModifierChanged() )
         [ #  # ][ #  # ]
     907                 :            :         {
     908                 :            :             // trigger redraw if mouse over state has changed
     909   [ #  #  #  # ]:          0 :             if( IsNativeControlSupported(CTRL_SPINBOX, PART_ENTIRE_CONTROL) ||
                 [ #  # ]
     910                 :          0 :                 IsNativeControlSupported(CTRL_SPINBOX, PART_ALL_BUTTONS) )
     911                 :            :             {
     912         [ #  # ]:          0 :                 Rectangle* pRect = ImplFindPartRect( GetPointerPosPixel() );
     913         [ #  # ]:          0 :                 Rectangle* pLastRect = ImplFindPartRect( GetLastPointerPosPixel() );
     914 [ #  # ][ #  # ]:          0 :                 if( pRect != pLastRect || (pMouseEvt->IsLeaveWindow() || pMouseEvt->IsEnterWindow()) )
         [ #  # ][ #  # ]
     915                 :            :                 {
     916                 :            :                     // FIXME: this is currently only on aqua
     917                 :            :                     // check for other platforms that need similar handling
     918   [ #  #  #  #  :          0 :                     if( ImplGetSVData()->maNWFData.mbNoFocusRects &&
           #  # ][ #  # ]
     919                 :          0 :                         IsNativeWidgetEnabled() &&
     920                 :          0 :                         IsNativeControlSupported( CTRL_EDITBOX, PART_ENTIRE_CONTROL ) )
     921                 :            :                     {
     922                 :          0 :                         ImplInvalidateOutermostBorder( this );
     923                 :            :                     }
     924                 :            :                     else
     925                 :            :                     {
     926                 :            :                         // paint directly
     927         [ #  # ]:          0 :                         Region aRgn( GetActiveClipRegion() );
     928         [ #  # ]:          0 :                         if( pLastRect )
     929                 :            :                         {
     930 [ #  # ][ #  # ]:          0 :                             SetClipRegion( *pLastRect );
                 [ #  # ]
     931         [ #  # ]:          0 :                             Paint( *pLastRect );
     932         [ #  # ]:          0 :                             SetClipRegion( aRgn );
     933                 :            :                         }
     934         [ #  # ]:          0 :                         if( pRect )
     935                 :            :                         {
     936 [ #  # ][ #  # ]:          0 :                             SetClipRegion( *pRect );
                 [ #  # ]
     937         [ #  # ]:          0 :                             Paint( *pRect );
     938         [ #  # ]:          0 :                             SetClipRegion( aRgn );
     939         [ #  # ]:          0 :                         }
     940                 :            :                     }
     941                 :            :                 }
     942                 :            :             }
     943                 :            :         }
     944                 :            :     }
     945                 :            : 
     946         [ #  # ]:          0 :     return nDone ? nDone : Edit::PreNotify(rNEvt);
     947                 :            : }
     948                 :            : 
     949                 :            : // -----------------------------------------------------------------------
     950                 :            : 
     951                 :          0 : void SpinField::EndDropDown()
     952                 :            : {
     953                 :          0 :     mbInDropDown = sal_False;
     954 [ #  # ][ #  # ]:          0 :     Paint( Rectangle( Point(), GetOutputSizePixel() ) );
     955                 :          0 : }
     956                 :            : 
     957                 :            : // -----------------------------------------------------------------------
     958                 :            : 
     959                 :          0 : sal_Bool SpinField::ShowDropDown( sal_Bool )
     960                 :            : {
     961                 :          0 :     return sal_False;
     962                 :            : }
     963                 :            : 
     964                 :            : // -----------------------------------------------------------------------
     965                 :            : 
     966                 :         88 : Size SpinField::CalcMinimumSize() const
     967                 :            : {
     968                 :         88 :     Size aSz = Edit::CalcMinimumSize();
     969                 :            : 
     970         [ -  + ]:         88 :     if ( GetStyle() & WB_DROPDOWN )
     971                 :          0 :         aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize();
     972         [ -  + ]:         88 :     if ( GetStyle() & WB_SPIN )
     973                 :          0 :         aSz.Width() += maUpperRect.GetWidth();
     974                 :            : 
     975                 :         88 :     return aSz;
     976                 :            : }
     977                 :            : 
     978                 :            : // -----------------------------------------------------------------------
     979                 :            : 
     980                 :          0 : Size SpinField::GetOptimalSize(WindowSizeType eType) const
     981                 :            : {
     982         [ #  # ]:          0 :     switch (eType) {
     983                 :            :     case WINDOWSIZE_MINIMUM:
     984                 :          0 :         return CalcMinimumSize();
     985                 :            :     default:
     986                 :          0 :         return Edit::GetOptimalSize( eType );
     987                 :            :     }
     988                 :            : }
     989                 :            : 
     990                 :            : // -----------------------------------------------------------------------
     991                 :            : 
     992                 :         88 : Size SpinField::CalcSize( sal_uInt16 nChars ) const
     993                 :            : {
     994                 :         88 :     Size aSz = Edit::CalcSize( nChars );
     995                 :            : 
     996         [ -  + ]:         88 :     if ( GetStyle() & WB_DROPDOWN )
     997                 :          0 :         aSz.Width() += GetSettings().GetStyleSettings().GetScrollBarSize();
     998         [ -  + ]:         88 :     if ( GetStyle() & WB_SPIN )
     999                 :          0 :         aSz.Width() += GetSettings().GetStyleSettings().GetSpinSize();
    1000                 :            : 
    1001                 :         88 :     return aSz;
    1002                 :            : }
    1003                 :            : 
    1004                 :            : // --------------------------------------------------------------------
    1005                 :            : 
    1006                 :          0 : IMPL_LINK( SpinField, ImplTimeout, Timer*, pTimer )
    1007                 :            : {
    1008         [ #  # ]:          0 :     if ( pTimer->GetTimeout() == GetSettings().GetMouseSettings().GetButtonStartRepeat() )
    1009                 :            :     {
    1010                 :          0 :         pTimer->SetTimeout( GetSettings().GetMouseSettings().GetButtonRepeat() );
    1011                 :          0 :         pTimer->Start();
    1012                 :            :     }
    1013                 :            :     else
    1014                 :            :     {
    1015         [ #  # ]:          0 :         if ( mbInitialUp )
    1016                 :          0 :             Up();
    1017                 :            :         else
    1018                 :          0 :             Down();
    1019                 :            :     }
    1020                 :          0 :     return 0;
    1021                 :            : }
    1022                 :            : 
    1023                 :            : // -----------------------------------------------------------------------
    1024                 :            : 
    1025                 :          0 : void SpinField::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags )
    1026                 :            : {
    1027                 :          0 :     Edit::Draw( pDev, rPos, rSize, nFlags );
    1028                 :            : 
    1029                 :          0 :     WinBits nFieldStyle = GetStyle();
    1030 [ #  # ][ #  # ]:          0 :     if ( !(nFlags & WINDOW_DRAW_NOCONTROLS ) && ( nFieldStyle & (WB_SPIN|WB_DROPDOWN) ) )
    1031                 :            :     {
    1032         [ #  # ]:          0 :         Point aPos = pDev->LogicToPixel( rPos );
    1033         [ #  # ]:          0 :         Size aSize = pDev->LogicToPixel( rSize );
    1034                 :          0 :         OutDevType eOutDevType = pDev->GetOutDevType();
    1035         [ #  # ]:          0 :         AllSettings aOldSettings = pDev->GetSettings();
    1036                 :            : 
    1037         [ #  # ]:          0 :         pDev->Push();
    1038         [ #  # ]:          0 :         pDev->SetMapMode();
    1039                 :            : 
    1040         [ #  # ]:          0 :         if ( eOutDevType == OUTDEV_PRINTER )
    1041                 :            :         {
    1042         [ #  # ]:          0 :             StyleSettings aStyleSettings = aOldSettings.GetStyleSettings();
    1043         [ #  # ]:          0 :             aStyleSettings.SetFaceColor( COL_LIGHTGRAY );
    1044         [ #  # ]:          0 :             aStyleSettings.SetButtonTextColor( COL_BLACK );
    1045         [ #  # ]:          0 :             AllSettings aSettings( aOldSettings );
    1046         [ #  # ]:          0 :             aSettings.SetStyleSettings( aStyleSettings );
    1047 [ #  # ][ #  # ]:          0 :             pDev->SetSettings( aSettings );
                 [ #  # ]
    1048                 :            :         }
    1049                 :            : 
    1050 [ #  # ][ #  # ]:          0 :         Rectangle aDD, aUp, aDown;
                 [ #  # ]
    1051         [ #  # ]:          0 :         ImplCalcButtonAreas( pDev, aSize, aDD, aUp, aDown );
    1052         [ #  # ]:          0 :         aDD.Move( aPos.X(), aPos.Y() );
    1053         [ #  # ]:          0 :         aUp.Move( aPos.X(), aPos.Y() );
    1054                 :          0 :         aUp.Top()++;
    1055         [ #  # ]:          0 :         aDown.Move( aPos.X(), aPos.Y() );
    1056                 :            : 
    1057                 :          0 :         Color aButtonTextColor;
    1058 [ #  # ][ #  # ]:          0 :         if ( ( nFlags & WINDOW_DRAW_MONO ) || ( eOutDevType == OUTDEV_PRINTER ) )
    1059                 :          0 :             aButtonTextColor = Color( COL_BLACK );
    1060                 :            :         else
    1061                 :          0 :             aButtonTextColor = GetSettings().GetStyleSettings().GetButtonTextColor();
    1062                 :            : 
    1063 [ #  # ][ #  # ]:          0 :         if ( GetStyle() & WB_DROPDOWN )
    1064                 :            :         {
    1065                 :          0 :             DecorationView aView( pDev );
    1066                 :          0 :             sal_uInt16 nStyle = BUTTON_DRAW_NOLIGHTBORDER;
    1067         [ #  # ]:          0 :             Rectangle aInnerRect = aView.DrawButton( aDD, nStyle );
    1068                 :          0 :             SymbolType eSymbol = SYMBOL_SPIN_DOWN;
    1069         [ #  # ]:          0 :             if ( GetSettings().GetStyleSettings().GetOptions() & STYLE_OPTION_SPINUPDOWN )
    1070                 :          0 :                 eSymbol = SYMBOL_SPIN_UPDOWN;
    1071                 :            : 
    1072 [ #  # ][ #  # ]:          0 :             nStyle = ( IsEnabled() || ( nFlags & WINDOW_DRAW_NODISABLE ) ) ? 0 : SYMBOL_DRAW_DISABLE;
                 [ #  # ]
    1073         [ #  # ]:          0 :             aView.DrawSymbol( aInnerRect, eSymbol, aButtonTextColor, nStyle );
    1074                 :            :         }
    1075                 :            : 
    1076 [ #  # ][ #  # ]:          0 :         if ( GetStyle() & WB_SPIN )
    1077                 :            :         {
    1078         [ #  # ]:          0 :             ImplDrawSpinButton( pDev, aUp, aDown, sal_False, sal_False, sal_True, sal_True );
    1079                 :            :         }
    1080                 :            : 
    1081         [ #  # ]:          0 :         pDev->Pop();
    1082 [ #  # ][ #  # ]:          0 :         pDev->SetSettings( aOldSettings );
    1083                 :            :     }
    1084                 :          0 : }
    1085                 :            : 
    1086                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10