LCOV - code coverage report
Current view: top level - vcl/source/window - toolbox.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1115 2896 38.5 %
Date: 2014-04-11 Functions: 64 116 55.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <tools/debug.hxx>
      21             : #include <tools/rc.h>
      22             : #include <tools/poly.hxx>
      23             : 
      24             : #include <vcl/event.hxx>
      25             : #include <vcl/decoview.hxx>
      26             : #include <vcl/accel.hxx>
      27             : #include <vcl/svapp.hxx>
      28             : #include <vcl/help.hxx>
      29             : #include <vcl/spin.h>
      30             : #include <vcl/toolbox.hxx>
      31             : #include <vcl/bitmap.hxx>
      32             : #include <vcl/mnemonic.hxx>
      33             : #include <vcl/gradient.hxx>
      34             : #include <vcl/layout.hxx>
      35             : #include <vcl/menu.hxx>
      36             : #include <vcl/settings.hxx>
      37             : 
      38             : #include <svdata.hxx>
      39             : #include <window.h>
      40             : #include <toolbox.h>
      41             : #include <salframe.hxx>
      42             : #if defined WNT
      43             : #include <svsys.h>
      44             : #endif
      45             : 
      46             : #include <cstdlib>
      47             : #include <string.h>
      48             : #include <vector>
      49             : #include <math.h>
      50             : 
      51             : #define SMALLBUTTON_HSIZE           7
      52             : #define SMALLBUTTON_VSIZE           7
      53             : 
      54             : #define SMALLBUTTON_OFF_NORMAL_X    3
      55             : #define SMALLBUTTON_OFF_NORMAL_Y    3
      56             : 
      57             : #define TB_TEXTOFFSET           2
      58             : #define TB_IMAGETEXTOFFSET      3
      59             : #define TB_LINESPACING          3
      60             : #define TB_SPIN_SIZE            14
      61             : #define TB_SPIN_OFFSET          2
      62             : #define TB_BORDER_OFFSET1       4
      63             : #define TB_BORDER_OFFSET2       2
      64             : #define TB_CUSTOMIZE_OFFSET     2
      65             : #define TB_RESIZE_OFFSET        3
      66             : #define TB_MAXLINES             5
      67             : #define TB_MAXNOSCROLL          32765
      68             : 
      69             : #define TB_MIN_WIN_WIDTH        20
      70             : 
      71             : #define TB_CALCMODE_HORZ        1
      72             : #define TB_CALCMODE_VERT        2
      73             : #define TB_CALCMODE_FLOAT       3
      74             : 
      75             : #define TB_WBLINESIZING         (WB_SIZEABLE | WB_DOCKABLE | WB_SCROLL)
      76             : 
      77             : #define DOCK_LINEHSIZE          ((sal_uInt16)0x0001)
      78             : #define DOCK_LINEVSIZE          ((sal_uInt16)0x0002)
      79             : #define DOCK_LINERIGHT          ((sal_uInt16)0x1000)
      80             : #define DOCK_LINEBOTTOM         ((sal_uInt16)0x2000)
      81             : #define DOCK_LINELEFT           ((sal_uInt16)0x4000)
      82             : #define DOCK_LINETOP            ((sal_uInt16)0x8000)
      83             : #define DOCK_LINEOFFSET         3
      84             : 
      85             : static void ImplDrawButton( ToolBox* pThis, const Rectangle &rRect, sal_uInt16 highlight, bool bChecked, bool bEnabled, bool bIsWindow );
      86             : 
      87             : typedef ::std::vector< ToolBox* > ImplTBList;
      88             : 
      89             : class ImplTBDragMgr
      90             : {
      91             : private:
      92             :     ImplTBList*     mpBoxList;
      93             :     ToolBox*        mpDragBox;
      94             :     Point           maMouseOff;
      95             :     Rectangle       maRect;
      96             :     Rectangle       maStartRect;
      97             :     Accelerator     maAccel;
      98             :     long            mnMinWidth;
      99             :     long            mnMaxWidth;
     100             :     sal_uInt16          mnLineMode;
     101             :     sal_uInt16          mnStartLines;
     102             :     void*           mpCustomizeData;
     103             :     bool            mbResizeMode;
     104             :     bool            mbShowDragRect;
     105             : 
     106             : public:
     107             :                     ImplTBDragMgr();
     108             :                     ~ImplTBDragMgr();
     109             : 
     110        6103 :     void            push_back( ToolBox* pBox )
     111        6103 :                         { mpBoxList->push_back( pBox ); }
     112        6089 :     void            erase( ToolBox* pBox )
     113             :                     {
     114       10754 :                         for ( ImplTBList::iterator it = mpBoxList->begin(); it != mpBoxList->end(); ++it ) {
     115       10754 :                             if ( *it == pBox ) {
     116        6089 :                                 mpBoxList->erase( it );
     117        6089 :                                 break;
     118             :                             }
     119             :                         }
     120        6089 :                     }
     121       10863 :     size_t          size() const
     122       10863 :                     { return mpBoxList->size(); }
     123             : 
     124             :     ToolBox*        FindToolBox( const Rectangle& rRect );
     125             : 
     126             :     void            StartDragging( ToolBox* pDragBox,
     127             :                                    const Point& rPos, const Rectangle& rRect,
     128             :                                    sal_uInt16 nLineMode, bool bResizeItem,
     129             :                                    void* pData = NULL );
     130             :     void            Dragging( const Point& rPos );
     131             :     void            EndDragging( bool bOK = true );
     132           0 :     void            HideDragRect() { if ( mbShowDragRect ) mpDragBox->HideTracking(); }
     133             :     void            UpdateDragRect();
     134             :                     DECL_LINK( SelectHdl, Accelerator* );
     135             : };
     136             : 
     137        6103 : static ImplTBDragMgr* ImplGetTBDragMgr()
     138             : {
     139        6103 :     ImplSVData* pSVData = ImplGetSVData();
     140        6103 :     if ( !pSVData->maCtrlData.mpTBDragMgr )
     141        1909 :         pSVData->maCtrlData.mpTBDragMgr = new ImplTBDragMgr;
     142        6103 :     return pSVData->maCtrlData.mpTBDragMgr;
     143             : }
     144             : 
     145      146263 : int ToolBox::ImplGetDragWidth( ToolBox* pThis )
     146             : {
     147             :     #define TB_DRAGWIDTH 8  // the default width of the grip
     148             : 
     149      146263 :     int width = TB_DRAGWIDTH;
     150      146263 :     if( pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
     151             :     {
     152             : 
     153           0 :         ImplControlValue aControlValue;
     154           0 :         Point aPoint;
     155           0 :         Rectangle aContent, aBound;
     156           0 :         Rectangle aArea( aPoint, pThis->GetOutputSizePixel() );
     157             : 
     158           0 :         if ( pThis->GetNativeControlRegion(CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_VERT : PART_THUMB_HORZ,
     159           0 :                 aArea, 0, aControlValue, OUString(), aBound, aContent) )
     160             :         {
     161           0 :             width = pThis->mbHorz ? aContent.GetWidth() : aContent.GetHeight();
     162           0 :         }
     163             :     }
     164      146263 :     return width;
     165             : }
     166             : 
     167      139498 : ButtonType determineButtonType( ImplToolItem* pItem, ButtonType defaultType )
     168             : {
     169      139498 :     ButtonType tmpButtonType = defaultType;
     170      139498 :     ToolBoxItemBits nBits( pItem->mnBits & 0x300 );
     171      139498 :     if ( nBits & TIB_TEXTICON ) // item has custom setting
     172             :     {
     173           0 :         tmpButtonType = BUTTON_SYMBOLTEXT;
     174           0 :         if ( nBits == TIB_TEXT_ONLY )
     175           0 :             tmpButtonType = BUTTON_TEXT;
     176           0 :         else if ( nBits == TIB_ICON_ONLY )
     177           0 :             tmpButtonType = BUTTON_SYMBOL;
     178             :     }
     179      139498 :     return tmpButtonType;
     180             : }
     181             : 
     182        8112 : void ToolBox::ImplUpdateDragArea( ToolBox *pThis )
     183             : {
     184        8112 :     ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
     185        8112 :     if( pWrapper )
     186             :     {
     187        4795 :         if ( pThis->ImplIsFloatingMode() || pWrapper->IsLocked() )
     188           0 :             pWrapper->SetDragArea( Rectangle() );
     189             :         else
     190             :         {
     191        4795 :             if( pThis->meAlign == WINDOWALIGN_TOP || pThis->meAlign == WINDOWALIGN_BOTTOM )
     192        4795 :                 pWrapper->SetDragArea( Rectangle( 0, 0, ImplGetDragWidth( pThis ), pThis->GetOutputSizePixel().Height() ) );
     193             :             else
     194           0 :                 pWrapper->SetDragArea( Rectangle( 0, 0, pThis->GetOutputSizePixel().Width(), ImplGetDragWidth( pThis ) ) );
     195             :         }
     196             :     }
     197        8112 : }
     198             : 
     199      115970 : void ToolBox::ImplCalcBorder( WindowAlign eAlign, long& rLeft, long& rTop,
     200             :                               long& rRight, long& rBottom, const ToolBox *pThis )
     201             : {
     202      115970 :     if( pThis->ImplIsFloatingMode() || !(pThis->mnWinStyle & WB_BORDER) )
     203             :     {
     204             :         // no border in floating mode
     205        9115 :         rLeft = rTop = rRight = rBottom = 0;
     206      125085 :         return;
     207             :     }
     208             : 
     209      106855 :     ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
     210             : 
     211             :     // reserve dragarea only for dockable toolbars
     212      106855 :     int    dragwidth = ( pWrapper && !pWrapper->IsLocked() ) ? ImplGetDragWidth( (ToolBox*)pThis ) : 0;
     213             : 
     214             :     // no shadow border for dockable toolbars
     215      106855 :     int    borderwidth = pWrapper ? 0: 2;
     216             : 
     217      106855 :     if ( eAlign == WINDOWALIGN_TOP )
     218             :     {
     219      101618 :         rLeft   = borderwidth+dragwidth;
     220      101618 :         rTop    = borderwidth;
     221      101618 :         rRight  = borderwidth;
     222      101618 :         rBottom = 0;
     223             :     }
     224        5237 :     else if ( eAlign == WINDOWALIGN_LEFT )
     225             :     {
     226           0 :         rLeft   = borderwidth;
     227           0 :         rTop    = borderwidth+dragwidth;
     228           0 :         rRight  = 0;
     229           0 :         rBottom = borderwidth;
     230             :     }
     231        5237 :     else if ( eAlign == WINDOWALIGN_BOTTOM )
     232             :     {
     233        5237 :         rLeft   = borderwidth+dragwidth;
     234        5237 :         rTop    = 0;
     235        5237 :         rRight  = borderwidth;
     236        5237 :         rBottom = borderwidth;
     237             :     }
     238             :     else
     239             :     {
     240           0 :         rLeft   = 0;
     241           0 :         rTop    = borderwidth+dragwidth;
     242           0 :         rRight  = borderwidth;
     243           0 :         rBottom = borderwidth;
     244             :     }
     245             : }
     246             : 
     247      182724 : static void ImplCheckUpdate( ToolBox *pThis )
     248             : {
     249             :     // remove any pending invalidates to avoid
     250             :     // have them triggered when paint is locked (see mpData->mbIsPaintLocked)
     251             :     // which would result in erasing the background only and not painting any items
     252             :     // this must not be done when we're already in Paint()
     253             : 
     254             :     // this is only required for transparent toolbars (see ImplDrawTransparentBackground() )
     255      182724 :     if( !pThis->IsBackground() && pThis->HasPaintEvent() && !pThis->IsInPaint() )
     256           0 :         pThis->Update();
     257      182724 : }
     258             : 
     259       10054 : void ToolBox::ImplDrawGrip( ToolBox* pThis )
     260             : {
     261       10054 :     ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
     262       10054 :     if( pWrapper && !pWrapper->GetDragArea().IsEmpty() )
     263             :     {
     264             :         // execute pending paint requests
     265        8288 :         ImplCheckUpdate( pThis );
     266             : 
     267        8288 :         bool bNativeOk = false;
     268        8288 :         if( pThis->IsNativeControlSupported( CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_HORZ : PART_THUMB_VERT ) )
     269             :         {
     270           0 :             ToolbarValue        aToolbarValue;
     271           0 :             aToolbarValue.maGripRect = pWrapper->GetDragArea();
     272           0 :             Point aPt;
     273           0 :             Rectangle           aCtrlRegion( aPt, pThis->GetOutputSizePixel() );
     274           0 :             ControlState        nState = CTRL_STATE_ENABLED;
     275             : 
     276             :             bNativeOk = pThis->DrawNativeControl( CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_VERT : PART_THUMB_HORZ,
     277           0 :                                             aCtrlRegion, nState, aToolbarValue, OUString() );
     278             :         }
     279             : 
     280        8288 :         if( bNativeOk )
     281       10054 :             return;
     282             : 
     283        8288 :         const StyleSettings&    rStyleSettings = pThis->GetSettings().GetStyleSettings();
     284        8288 :         pThis->SetLineColor( rStyleSettings.GetShadowColor() );
     285             : 
     286        8288 :         Size aSz ( pThis->GetOutputSizePixel() );
     287             : 
     288        8288 :         if ( pThis->meAlign == WINDOWALIGN_TOP || pThis->meAlign == WINDOWALIGN_BOTTOM )
     289             :         {
     290        8288 :             int height = (int) (0.6 * aSz.Height() + 0.5);
     291        8288 :             int i = (aSz.Height() - height) / 2;
     292        8288 :             height += i;
     293       58016 :             while( i <= height )
     294             :             {
     295       41440 :                 int x = ImplGetDragWidth( pThis ) / 2;
     296             : 
     297       41440 :                 pThis->DrawPixel( Point(x, i), rStyleSettings.GetDarkShadowColor() );
     298       41440 :                 pThis->DrawPixel( Point(x+1, i), rStyleSettings.GetShadowColor() );
     299             : 
     300       41440 :                 pThis->DrawPixel( Point(x, i+1), rStyleSettings.GetShadowColor() );
     301       41440 :                 pThis->DrawPixel( Point(x+1, i+1), rStyleSettings.GetFaceColor() );
     302       41440 :                 pThis->DrawPixel( Point(x+2, i+1), Color(COL_WHITE) );
     303             : 
     304       41440 :                 pThis->DrawPixel( Point(x+1, i+2), Color(COL_WHITE) );
     305       41440 :                 pThis->DrawPixel( Point(x+2, i+2), Color(COL_WHITE) );
     306       41440 :                 i+=4;
     307        8288 :             }
     308             :         }
     309             :         else
     310             :         {
     311           0 :             int width = (int) (0.6 * aSz.Width() + 0.5);
     312           0 :             int i = (aSz.Width() - width) / 2;
     313           0 :             width += i;
     314           0 :             while( i <= width )
     315             :             {
     316           0 :                 int y = ImplGetDragWidth(pThis) / 2;
     317             : 
     318           0 :                 pThis->DrawPixel( Point(i, y), rStyleSettings.GetDarkShadowColor() );
     319           0 :                 pThis->DrawPixel( Point(i+1, y), rStyleSettings.GetShadowColor() );
     320             : 
     321           0 :                 pThis->DrawPixel( Point(i, y+1), rStyleSettings.GetShadowColor() );
     322           0 :                 pThis->DrawPixel( Point(i+1, y+1), rStyleSettings.GetFaceColor() );
     323           0 :                 pThis->DrawPixel( Point(i+2, y+1), Color(COL_WHITE) );
     324             : 
     325           0 :                 pThis->DrawPixel( Point(i+1, y+2), Color(COL_WHITE) );
     326           0 :                 pThis->DrawPixel( Point(i+2, y+2), Color(COL_WHITE) );
     327           0 :                 i+=4;
     328             :             }
     329             :         }
     330             :     }
     331             : }
     332             : 
     333       81057 : void ToolBox::ImplDrawGradientBackground( ToolBox* pThis, ImplDockingWindowWrapper * )
     334             : {
     335             :     // draw a nice gradient
     336             : 
     337       81057 :     Color startCol, endCol;
     338       81057 :     startCol = pThis->GetSettings().GetStyleSettings().GetFaceGradientColor();
     339       81057 :     endCol = pThis->GetSettings().GetStyleSettings().GetFaceColor();
     340       81057 :     if( pThis->GetSettings().GetStyleSettings().GetHighContrastMode() )
     341             :         // no 'extreme' gradient when high contrast
     342           0 :         startCol = endCol;
     343             : 
     344       81057 :     Gradient g;
     345       81057 :     g.SetAngle( pThis->mbHorz ? 0 : 900 );
     346       81057 :     g.SetStyle( GradientStyle_LINEAR );
     347             : 
     348       81057 :     g.SetStartColor( startCol );
     349       81057 :     g.SetEndColor( endCol );
     350             : 
     351       81057 :     bool bLineColor = pThis->IsLineColor();
     352       81057 :     Color aOldCol = pThis->GetLineColor();
     353       81057 :     pThis->SetLineColor( pThis->GetSettings().GetStyleSettings().GetShadowColor() );
     354             : 
     355       81057 :     Size aFullSz( pThis->GetOutputSizePixel() );
     356       81057 :     Size aLineSz( aFullSz );
     357             : 
     358             :     // use the linesize only when floating
     359             :     // full window height is used when docked (single line)
     360       81057 :     if( pThis->ImplIsFloatingMode() )
     361             :     {
     362             :         long nLineSize;
     363           0 :         if( pThis->mbHorz )
     364             :         {
     365           0 :             nLineSize = pThis->mnMaxItemHeight;
     366           0 :             if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
     367           0 :                 nLineSize = pThis->mnWinHeight;
     368             : 
     369           0 :             aLineSz.Height() = nLineSize;
     370             :         }
     371             :         else
     372             :         {
     373           0 :             nLineSize = pThis->mnMaxItemWidth;
     374           0 :             aLineSz.Width() = nLineSize;
     375             :         }
     376             :     }
     377             : 
     378             :     long nLeft, nTop, nRight, nBottom;
     379       81057 :     ImplCalcBorder( pThis->meAlign, nLeft, nTop, nRight, nBottom, pThis );
     380             : 
     381       81057 :     Size aTopLineSz( aLineSz );
     382       81057 :     Size aBottomLineSz( aLineSz );
     383             : 
     384       81057 :     if ( pThis->mnWinStyle & WB_BORDER )
     385             :     {
     386       81057 :         if( pThis->mbHorz )
     387             :         {
     388       81057 :             aTopLineSz.Height() += TB_BORDER_OFFSET2 + nTop;
     389       81057 :             aBottomLineSz.Height() += TB_BORDER_OFFSET2 + nBottom;
     390             : 
     391       81057 :             if( pThis->mnCurLines == 1 )
     392       81057 :                 aTopLineSz.Height() += TB_BORDER_OFFSET2 + nBottom;
     393             :         }
     394             :         else
     395             :         {
     396           0 :             aTopLineSz.Width() += TB_BORDER_OFFSET1 + nLeft;
     397           0 :             aBottomLineSz.Width() += TB_BORDER_OFFSET1 + nRight;
     398             : 
     399           0 :             if( pThis->mnCurLines == 1 )
     400           0 :                 aTopLineSz.Width() += TB_BORDER_OFFSET1 + nLeft;
     401             :         }
     402             :     }
     403             : 
     404       81057 :     if ( pThis->mnWinStyle & WB_LINESPACING )
     405             :     {
     406       81057 :         if( pThis->mbHorz )
     407             :         {
     408       81057 :             aLineSz.Height() += TB_LINESPACING;
     409       81057 :             if( pThis->mnCurLines > 1 )
     410           0 :                 aTopLineSz.Height() += TB_LINESPACING;
     411             :         }
     412             :         else
     413             :         {
     414           0 :             aLineSz.Width() += TB_LINESPACING;
     415           0 :             if( pThis->mnCurLines > 1 )
     416           0 :                 aTopLineSz.Width() += TB_LINESPACING;
     417             :         }
     418             :     }
     419             : 
     420       81057 :     if( pThis->mbHorz )
     421             :     {
     422       81057 :         long y = 0;
     423             : 
     424       81057 :         pThis->DrawGradient( Rectangle( 0, y, aTopLineSz.Width(), y+aTopLineSz.Height()), g );
     425       81057 :         y += aTopLineSz.Height();
     426             : 
     427      162114 :         while( y < (pThis->mnDY - aBottomLineSz.Height()) )
     428             :         {
     429           0 :             pThis->DrawGradient( Rectangle( 0, y, aLineSz.Width(), y+aLineSz.Height()), g);
     430           0 :             y += aLineSz.Height();
     431             :         }
     432             : 
     433       81057 :         pThis->DrawGradient( Rectangle( 0, y, aBottomLineSz.Width(), y+aBottomLineSz.Height()), g );
     434             :     }
     435             :     else
     436             :     {
     437           0 :         long x = 0;
     438             : 
     439           0 :         pThis->DrawGradient( Rectangle( x, 0, x+aTopLineSz.Width(), aTopLineSz.Height()), g );
     440           0 :         x += aTopLineSz.Width();
     441             : 
     442           0 :         while( x < (pThis->mnDX - aBottomLineSz.Width()) )
     443             :         {
     444           0 :             pThis->DrawGradient( Rectangle( x, 0, x+aLineSz.Width(), aLineSz.Height()), g);
     445           0 :             x += aLineSz.Width();
     446             :         }
     447             : 
     448           0 :         pThis->DrawGradient( Rectangle( x, 0, x+aBottomLineSz.Width(), aBottomLineSz.Height()), g );
     449             :     }
     450             : 
     451       81057 :     if( bLineColor )
     452       81057 :         pThis->SetLineColor( aOldCol );
     453             : 
     454       81057 : }
     455             : 
     456           0 : bool ToolBox::ImplDrawNativeBackground( ToolBox* pThis, const Region & )
     457             : {
     458             :     // use NWF
     459           0 :     Point aPt;
     460           0 :     Rectangle aCtrlRegion( aPt, pThis->GetOutputSizePixel() );
     461           0 :     ControlState  nState = CTRL_STATE_ENABLED;
     462             : 
     463             :     return pThis->DrawNativeControl( CTRL_TOOLBAR, pThis->mbHorz ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
     464           0 :                                     aCtrlRegion, nState, ImplControlValue(), OUString() );
     465             : }
     466             : 
     467           0 : void ToolBox::ImplDrawTransparentBackground( ToolBox* pThis, const Region &rRegion )
     468             : {
     469             :     // just invalidate to trigger paint of the parent
     470             : 
     471           0 :     const bool        bOldPaintLock = pThis->mpData->mbIsPaintLocked;
     472           0 :     pThis->mpData->mbIsPaintLocked = true;
     473             : 
     474             :     // send an invalidate to the first opaque parent and invalidate the whole hierarchy from there (noclipchildren)
     475           0 :     pThis->Invalidate( rRegion, INVALIDATE_UPDATE|INVALIDATE_NOCLIPCHILDREN );
     476             : 
     477           0 :     pThis->mpData->mbIsPaintLocked = bOldPaintLock;
     478           0 : }
     479             : 
     480        4513 : void ToolBox::ImplDrawConstantBackground( ToolBox* pThis, const Region &rRegion, bool bIsInPopupMode )
     481             : {
     482             :     // draw a constant color
     483        4513 :     if( !bIsInPopupMode )
     484             :         // default background
     485        4513 :         pThis->Erase( rRegion.GetBoundRect() );
     486             :     else
     487             :     {
     488             :         // use different color in popupmode
     489             :         pThis->DrawWallpaper( rRegion.GetBoundRect(),
     490           0 :             Wallpaper( pThis->GetSettings().GetStyleSettings().GetFaceGradientColor() ) );
     491             :     }
     492        4513 : }
     493             : 
     494       85570 : void ToolBox::ImplDrawBackground( ToolBox* pThis, const Rectangle &rRect )
     495             : {
     496             :     // execute pending paint requests
     497       85570 :     ImplCheckUpdate( pThis );
     498             : 
     499       85570 :     ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
     500       85570 :     bool bIsInPopupMode = pThis->ImplIsInPopupMode();
     501             : 
     502       85570 :     Region aPaintRegion( rRect );
     503             : 
     504             :     // make sure we do not invalidate/erase too much
     505       85570 :     if( pThis->IsInPaint() )
     506       85227 :         aPaintRegion.Intersect( pThis->GetActiveClipRegion() );
     507             : 
     508       85570 :     pThis->Push( PUSH_CLIPREGION );
     509       85570 :     pThis->IntersectClipRegion( aPaintRegion );
     510             : 
     511       85570 :     if( !pWrapper /*|| bIsInPopupMode*/ )
     512             :     {
     513             :         // no gradient for ordinary toolbars (not dockable)
     514        4513 :         if( !pThis->IsBackground() && !pThis->IsInPaint() )
     515           0 :             ImplDrawTransparentBackground( pThis, aPaintRegion );
     516             :         else
     517        4513 :             ImplDrawConstantBackground( pThis, aPaintRegion, bIsInPopupMode );
     518             :     }
     519             :     else
     520             :     {
     521             :         // toolbars known to the dockingmanager will be drawn using NWF or a gradient
     522             :         // docked toolbars are transparent and NWF is already used in the docking area which is their common background
     523             :         // so NWF is used here for floating toolbars only
     524       81057 :         bool bNativeOk = false;
     525       81057 :         if( pThis->ImplIsFloatingMode() && pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL) )
     526           0 :             bNativeOk = ImplDrawNativeBackground( pThis, aPaintRegion );
     527             : 
     528       81057 :         if( !bNativeOk )
     529             :         {
     530      247461 :             if( !pThis->IsBackground() ||
     531      315648 :                 ( pThis->GetAlign() == WINDOWALIGN_TOP && !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty() ) )
     532             :             {
     533           0 :                 if( !pThis->IsInPaint() )
     534           0 :                     ImplDrawTransparentBackground( pThis, aPaintRegion );
     535             :             }
     536             :             else
     537       81057 :                 ImplDrawGradientBackground( pThis, pWrapper );
     538             :         }
     539             :     }
     540             : 
     541             :     // restore clip region
     542       85570 :     pThis->Pop();
     543       85570 : }
     544             : 
     545       75517 : void ToolBox::ImplErase( ToolBox* pThis, const Rectangle &rRect, bool bHighlight, bool bHasOpenPopup )
     546             : {
     547             :     // the background of non NWF buttons is painted in a constant color
     548             :     // to have the same highlight color (transparency in DrawSelectionBackground())
     549             :     // items with open popups will also painted using a constant color
     550       76433 :     if( !pThis->mpData->mbNativeButtons &&
     551       75516 :         (bHighlight || ! (((Window*) pThis)->GetStyle() & WB_3DLOOK ) ) )
     552             :     {
     553         916 :         if( (((Window*) pThis)->GetStyle() & WB_3DLOOK ) )
     554             :         {
     555           1 :             pThis->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
     556           1 :             pThis->SetLineColor();
     557           1 :             if( bHasOpenPopup )
     558             :                 // choose the same color as the popup will use
     559           0 :                 pThis->SetFillColor( pThis->GetSettings().GetStyleSettings().GetFaceGradientColor() );
     560             :             else
     561           1 :                 pThis->SetFillColor( Color( COL_WHITE ) );
     562             : 
     563           1 :             pThis->DrawRect( rRect );
     564           1 :             pThis->Pop();
     565             :         }
     566             :         else
     567         915 :             ImplDrawBackground( pThis, rRect );
     568             :     }
     569             :     else
     570       74601 :         ImplDrawBackground( pThis, rRect );
     571       75517 : }
     572             : 
     573        8288 : void ToolBox::ImplDrawBorder( ToolBox* pWin )
     574             : {
     575        8288 :     const StyleSettings&    rStyleSettings = pWin->GetSettings().GetStyleSettings();
     576        8288 :     long                    nDX = pWin->mnDX;
     577        8288 :     long                    nDY = pWin->mnDY;
     578             : 
     579        8288 :     ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pWin );
     580             : 
     581             :     // draw borders for ordinary toolbars only (not dockable)
     582        8288 :     if( pWrapper )
     583       16576 :         return;
     584             : 
     585           0 :     if ( pWin->meAlign == WINDOWALIGN_BOTTOM )
     586             :     {
     587             :         // draw bottom border
     588           0 :         pWin->SetLineColor( rStyleSettings.GetShadowColor() );
     589           0 :         pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
     590           0 :         pWin->SetLineColor( rStyleSettings.GetLightColor() );
     591           0 :         pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
     592             :     }
     593             :     else
     594             :     {
     595             :         // draw top border
     596           0 :         pWin->SetLineColor( rStyleSettings.GetShadowColor() );
     597           0 :         pWin->DrawLine( Point( 0, 0 ), Point( nDX-1, 0 ) );
     598           0 :         pWin->SetLineColor( rStyleSettings.GetLightColor() );
     599           0 :         pWin->DrawLine( Point( 0, 1 ), Point( nDX-1, 1 ) );
     600             : 
     601           0 :         if ( (pWin->meAlign == WINDOWALIGN_LEFT) || (pWin->meAlign == WINDOWALIGN_RIGHT) )
     602             :         {
     603           0 :             if ( pWin->meAlign == WINDOWALIGN_LEFT )
     604             :             {
     605             :                 // draw left-bottom border
     606           0 :                 pWin->SetLineColor( rStyleSettings.GetShadowColor() );
     607           0 :                 pWin->DrawLine( Point( 0, 0 ), Point( 0, nDY-1 ) );
     608           0 :                 pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
     609           0 :                 pWin->SetLineColor( rStyleSettings.GetLightColor() );
     610           0 :                 pWin->DrawLine( Point( 1, 1 ), Point( 1, nDY-3 ) );
     611           0 :                 pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
     612             :             }
     613             :             else
     614             :             {
     615             :                 // draw right-bottom border
     616           0 :                 pWin->SetLineColor( rStyleSettings.GetShadowColor() );
     617           0 :                 pWin->DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-3 ) );
     618           0 :                 pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-2, nDY-2 ) );
     619           0 :                 pWin->SetLineColor( rStyleSettings.GetLightColor() );
     620           0 :                 pWin->DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
     621           0 :                 pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
     622             :             }
     623             :         }
     624             :     }
     625             : 
     626           0 :     if ( pWin->meAlign == WINDOWALIGN_BOTTOM || pWin->meAlign == WINDOWALIGN_TOP )
     627             :     {
     628             :         // draw right border
     629           0 :         pWin->SetLineColor( rStyleSettings.GetShadowColor() );
     630           0 :         pWin->DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-1 ) );
     631           0 :         pWin->SetLineColor( rStyleSettings.GetLightColor() );
     632           0 :         pWin->DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
     633             :     }
     634             : }
     635             : 
     636         358 : static bool ImplIsFixedControl( const ImplToolItem *pItem )
     637             : {
     638         358 :     return ( pItem->mpWindow &&
     639           0 :             (pItem->mpWindow->GetType() == WINDOW_FIXEDTEXT ||
     640           0 :              pItem->mpWindow->GetType() == WINDOW_FIXEDLINE ||
     641         358 :              pItem->mpWindow->GetType() == WINDOW_GROUPBOX) );
     642             : }
     643             : 
     644           1 : const ImplToolItem *ToolBox::ImplGetFirstClippedItem( const ToolBox* pThis )
     645             : {
     646           1 :     std::vector< ImplToolItem >::const_iterator it;
     647           1 :     it = pThis->mpData->m_aItems.begin();
     648          42 :     while ( it != pThis->mpData->m_aItems.end() )
     649             :     {
     650          40 :         if( it->IsClipped() )
     651           0 :             return &(*it);
     652          40 :         ++it;
     653             :     }
     654           1 :     return NULL;
     655             : }
     656             : 
     657       26801 : Size ToolBox::ImplCalcSize( const ToolBox* pThis, sal_uInt16 nCalcLines, sal_uInt16 nCalcMode )
     658             : {
     659             :     long            nMax;
     660       26801 :     long            nLeft = 0;
     661       26801 :     long            nTop = 0;
     662       26801 :     long            nRight = 0;
     663       26801 :     long            nBottom = 0;
     664       26801 :     Size            aSize;
     665       26801 :     WindowAlign     eOldAlign = pThis->meAlign;
     666       26801 :     bool            bOldHorz = pThis->mbHorz;
     667       26801 :     bool            bOldAssumeDocked = pThis->mpData->mbAssumeDocked;
     668       26801 :     bool            bOldAssumeFloating = pThis->mpData->mbAssumeFloating;
     669             : 
     670       26801 :     if ( nCalcMode )
     671             :     {
     672           0 :         bool bOldFloatingMode = pThis->ImplIsFloatingMode();
     673             : 
     674           0 :         pThis->mpData->mbAssumeDocked = false;
     675           0 :         pThis->mpData->mbAssumeFloating = false;
     676             : 
     677           0 :         if ( nCalcMode == TB_CALCMODE_HORZ )
     678             :         {
     679           0 :             pThis->mpData->mbAssumeDocked = true;   // force non-floating mode during calculation
     680           0 :             ImplCalcBorder( WINDOWALIGN_TOP, nLeft, nTop, nRight, nBottom, pThis );
     681           0 :             ((ToolBox*)pThis)->mbHorz = true;
     682           0 :             if ( pThis->mbHorz != bOldHorz )
     683           0 :                 ((ToolBox*)pThis)->meAlign = WINDOWALIGN_TOP;
     684             :         }
     685           0 :         else if ( nCalcMode == TB_CALCMODE_VERT )
     686             :         {
     687           0 :             pThis->mpData->mbAssumeDocked = true;   // force non-floating mode during calculation
     688           0 :             ImplCalcBorder( WINDOWALIGN_LEFT, nLeft, nTop, nRight, nBottom, pThis );
     689           0 :             ((ToolBox*)pThis)->mbHorz = false;
     690           0 :             if ( pThis->mbHorz != bOldHorz )
     691           0 :                 ((ToolBox*)pThis)->meAlign = WINDOWALIGN_LEFT;
     692             :         }
     693           0 :         else if ( nCalcMode == TB_CALCMODE_FLOAT )
     694             :         {
     695           0 :             pThis->mpData->mbAssumeFloating = true;   // force non-floating mode during calculation
     696           0 :             nLeft = nTop = nRight = nBottom = 0;
     697           0 :             ((ToolBox*)pThis)->mbHorz = true;
     698           0 :             if ( pThis->mbHorz != bOldHorz )
     699           0 :                 ((ToolBox*)pThis)->meAlign = WINDOWALIGN_TOP;
     700             :         }
     701             : 
     702           0 :         if ( (pThis->meAlign != eOldAlign) || (pThis->mbHorz != bOldHorz) ||
     703           0 :              (pThis->ImplIsFloatingMode() != bOldFloatingMode ) )
     704           0 :             ((ToolBox*)pThis)->mbCalc = true;
     705             :     }
     706             :     else
     707       26801 :         ImplCalcBorder( pThis->meAlign, nLeft, nTop, nRight, nBottom, pThis );
     708             : 
     709       26801 :     ((ToolBox*)pThis)->ImplCalcItem();
     710             : 
     711       26801 :     if( !nCalcMode && pThis->ImplIsFloatingMode() )
     712             :     {
     713           0 :         aSize = ImplCalcFloatSize( ((ToolBox*)pThis), nCalcLines );
     714             :     }
     715             :     else
     716             :     {
     717       26801 :         if ( pThis->mbHorz )
     718             :         {
     719       26801 :             if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
     720           9 :                 aSize.Height() = nCalcLines * pThis->mnWinHeight;
     721             :             else
     722       26792 :                 aSize.Height() = nCalcLines * pThis->mnMaxItemHeight;
     723             : 
     724       26801 :             if ( pThis->mnWinStyle & WB_LINESPACING )
     725       20279 :                 aSize.Height() += (nCalcLines-1)*TB_LINESPACING;
     726             : 
     727       26801 :             if ( pThis->mnWinStyle & WB_BORDER )
     728       20279 :                 aSize.Height() += (TB_BORDER_OFFSET2*2) + nTop + nBottom;
     729             : 
     730       26801 :             nMax = 0;
     731       26801 :             ((ToolBox*)pThis)->ImplCalcBreaks( TB_MAXNOSCROLL, &nMax, pThis->mbHorz );
     732       26801 :             if ( nMax )
     733       16580 :                 aSize.Width() += nMax;
     734             : 
     735       26801 :             if ( pThis->mnWinStyle & WB_BORDER )
     736       20279 :                 aSize.Width() += (TB_BORDER_OFFSET1*2) + nLeft + nRight;
     737             :         }
     738             :         else
     739             :         {
     740           0 :             aSize.Width() = nCalcLines * pThis->mnMaxItemWidth;
     741             : 
     742           0 :             if ( pThis->mnWinStyle & WB_LINESPACING )
     743           0 :                 aSize.Width() += (nCalcLines-1)*TB_LINESPACING;
     744             : 
     745           0 :             if ( pThis->mnWinStyle & WB_BORDER )
     746           0 :                 aSize.Width() += (TB_BORDER_OFFSET2*2) + nLeft + nRight;
     747             : 
     748           0 :             nMax = 0;
     749           0 :             ((ToolBox*)pThis)->ImplCalcBreaks( TB_MAXNOSCROLL, &nMax, pThis->mbHorz );
     750           0 :             if ( nMax )
     751           0 :                 aSize.Height() += nMax;
     752             : 
     753           0 :             if ( pThis->mnWinStyle & WB_BORDER )
     754           0 :                 aSize.Height() += (TB_BORDER_OFFSET1*2) + nTop + nBottom;
     755             :         }
     756             :     }
     757             :     // restore previous values
     758       26801 :     if ( nCalcMode )
     759             :     {
     760           0 :         pThis->mpData->mbAssumeDocked = bOldAssumeDocked;
     761           0 :         pThis->mpData->mbAssumeFloating = bOldAssumeFloating;
     762           0 :         if ( (pThis->meAlign != eOldAlign) || (pThis->mbHorz != bOldHorz) )
     763             :         {
     764           0 :             ((ToolBox*)pThis)->meAlign  = eOldAlign;
     765           0 :             ((ToolBox*)pThis)->mbHorz   = bOldHorz;
     766           0 :             ((ToolBox*)pThis)->mbCalc   = true;
     767             :         }
     768             :     }
     769             : 
     770       26801 :     return aSize;
     771             : }
     772             : 
     773           0 : void ToolBox::ImplCalcFloatSizes( ToolBox* pThis )
     774             : {
     775           0 :     if ( !pThis->maFloatSizes.empty() )
     776           0 :         return;
     777             : 
     778             :     // calculate the minimal size, i.e. where the biggest item just fits
     779           0 :     long            nCalcSize = 0;
     780             : 
     781           0 :     std::vector< ImplToolItem >::const_iterator it;
     782           0 :     it = pThis->mpData->m_aItems.begin();
     783           0 :     while ( it != pThis->mpData->m_aItems.end() )
     784             :     {
     785           0 :         if ( it->mbVisible )
     786             :         {
     787           0 :             if ( it->mpWindow )
     788             :             {
     789           0 :                 long nTempSize = it->mpWindow->GetSizePixel().Width();
     790           0 :                 if ( nTempSize > nCalcSize )
     791           0 :                     nCalcSize = nTempSize;
     792             :             }
     793             :             else
     794             :             {
     795           0 :                 if( it->maItemSize.Width() > nCalcSize )
     796           0 :                     nCalcSize = it->maItemSize.Width();
     797             :             }
     798             :         }
     799           0 :         ++it;
     800             :     }
     801             : 
     802             :     // calc an upper bound for ImplCalcBreaks below
     803           0 :     long upperBoundWidth = nCalcSize * pThis->mpData->m_aItems.size();
     804             : 
     805             :     sal_uInt16  nLines;
     806             :     sal_uInt16  nCalcLines;
     807             :     sal_uInt16  nTempLines;
     808             :     long    nMaxLineWidth;
     809           0 :     nCalcLines = pThis->ImplCalcBreaks( nCalcSize, &nMaxLineWidth, true );
     810             : 
     811           0 :     pThis->maFloatSizes.reserve( nCalcLines );
     812             : 
     813           0 :     nTempLines = nLines = nCalcLines;
     814           0 :     while ( nLines )
     815             :     {
     816           0 :         long nHeight = ImplCalcSize( pThis, nTempLines, TB_CALCMODE_FLOAT ).Height();
     817             : 
     818             :         ImplToolSize aSize;
     819           0 :         aSize.mnWidth  = nMaxLineWidth+(TB_BORDER_OFFSET1*2);
     820           0 :         aSize.mnHeight = nHeight;
     821           0 :         aSize.mnLines  = nTempLines;
     822           0 :         pThis->maFloatSizes.push_back( aSize );
     823           0 :         nLines--;
     824           0 :         if ( nLines )
     825             :         {
     826           0 :             do
     827             :             {
     828           0 :                 nCalcSize += pThis->mnMaxItemWidth;
     829           0 :                 nTempLines = pThis->ImplCalcBreaks( nCalcSize, &nMaxLineWidth, true );
     830             :             }
     831           0 :             while ( (nCalcSize < upperBoundWidth) && (nLines < nTempLines) && (nTempLines != 1) );
     832           0 :             if ( nTempLines < nLines )
     833           0 :                 nLines = nTempLines;
     834             :         }
     835             :     }
     836             : }
     837             : 
     838           0 : Size ToolBox::ImplCalcFloatSize( ToolBox* pThis, sal_uInt16& rLines )
     839             : {
     840           0 :     ImplCalcFloatSizes( pThis );
     841             : 
     842           0 :     if ( !rLines )
     843             :     {
     844           0 :         rLines = pThis->mnFloatLines;
     845           0 :         if ( !rLines )
     846           0 :             rLines = pThis->mnLines;
     847             :     }
     848             : 
     849           0 :     sal_uInt16 i = 0;
     850           0 :     while ( i + 1u < pThis->maFloatSizes.size() &&
     851           0 :             rLines < pThis->maFloatSizes[i].mnLines )
     852             :     {
     853           0 :         i++;
     854             :     }
     855             : 
     856           0 :     Size aSize( pThis->maFloatSizes[i].mnWidth,
     857           0 :                 pThis->maFloatSizes[i].mnHeight );
     858           0 :     rLines = pThis->maFloatSizes[i].mnLines;
     859             : 
     860           0 :     return aSize;
     861             : }
     862             : 
     863           0 : void ToolBox::ImplCalcMinMaxFloatSize( ToolBox* pThis, Size& rMinSize, Size& rMaxSize )
     864             : {
     865           0 :     ImplCalcFloatSizes( pThis );
     866             : 
     867           0 :     sal_uInt16 i = 0;
     868           0 :     rMinSize = Size( pThis->maFloatSizes[i].mnWidth, pThis->maFloatSizes[i].mnHeight );
     869           0 :     rMaxSize = Size( pThis->maFloatSizes[i].mnWidth, pThis->maFloatSizes[i].mnHeight );
     870           0 :     while ( ++i < pThis->maFloatSizes.size() )
     871             :     {
     872           0 :         if( pThis->maFloatSizes[i].mnWidth < rMinSize.Width() )
     873           0 :             rMinSize.Width() = pThis->maFloatSizes[i].mnWidth;
     874           0 :         if( pThis->maFloatSizes[i].mnHeight < rMinSize.Height() )
     875           0 :             rMinSize.Height() = pThis->maFloatSizes[i].mnHeight;
     876             : 
     877           0 :         if( pThis->maFloatSizes[i].mnWidth > rMaxSize.Width() )
     878           0 :             rMaxSize.Width() = pThis->maFloatSizes[i].mnWidth;
     879           0 :         if( pThis->maFloatSizes[i].mnHeight > rMaxSize.Height() )
     880           0 :             rMaxSize.Height() = pThis->maFloatSizes[i].mnHeight;
     881             :     }
     882           0 : }
     883             : 
     884           0 : void ToolBox::ImplSetMinMaxFloatSize( ToolBox *pThis )
     885             : {
     886           0 :     ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
     887           0 :     Size aMinSize, aMaxSize;
     888           0 :     ImplCalcMinMaxFloatSize( pThis, aMinSize, aMaxSize );
     889           0 :     if( pWrapper )
     890             :     {
     891           0 :         pWrapper->SetMinOutputSizePixel( aMinSize );
     892           0 :         pWrapper->SetMaxOutputSizePixel( aMaxSize );
     893           0 :         pWrapper->ShowTitleButton( TITLE_BUTTON_MENU, ( pThis->GetMenuType() & TOOLBOX_MENUTYPE_CUSTOMIZE) ? true : false );
     894             :     }
     895             :     else
     896             :     {
     897             :         // TODO: change SetMinOutputSizePixel to be not inline
     898           0 :         pThis->SetMinOutputSizePixel( aMinSize );
     899           0 :         pThis->SetMaxOutputSizePixel( aMaxSize );
     900             :     }
     901           0 : }
     902             : 
     903        5519 : sal_uInt16 ToolBox::ImplCalcLines( ToolBox* pThis, long nToolSize )
     904             : {
     905             :     long nLineHeight;
     906             : 
     907        5519 :     if ( pThis->mbHorz )
     908             :     {
     909        5519 :         if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
     910           0 :             nLineHeight = pThis->mnWinHeight;
     911             :         else
     912        5519 :             nLineHeight = pThis->mnMaxItemHeight;
     913             :     }
     914             :     else
     915           0 :         nLineHeight = pThis->mnMaxItemWidth;
     916             : 
     917        5519 :     if ( pThis->mnWinStyle & WB_BORDER )
     918        5519 :         nToolSize -= TB_BORDER_OFFSET2*2;
     919             : 
     920        5519 :     if ( pThis->mnWinStyle & WB_LINESPACING )
     921             :     {
     922        5519 :         nLineHeight += TB_LINESPACING;
     923        5519 :         nToolSize += TB_LINESPACING;
     924             :     }
     925             : 
     926             :     // #i91917# always report at least one line
     927        5519 :     long nLines = nToolSize/nLineHeight;
     928        5519 :     if( nLines < 1 )
     929         724 :         nLines = 1;
     930             : 
     931        5519 :     return static_cast<sal_uInt16>(nLines);
     932             : }
     933             : 
     934           0 : sal_uInt16 ToolBox::ImplTestLineSize( ToolBox* pThis, const Point& rPos )
     935             : {
     936           0 :     if ( !pThis->ImplIsFloatingMode() &&
     937           0 :          (!pThis->mbScroll || (pThis->mnLines > 1) || (pThis->mnCurLines > pThis->mnVisLines)) )
     938             :     {
     939           0 :         WindowAlign eAlign = pThis->GetAlign();
     940             : 
     941           0 :         if ( eAlign == WINDOWALIGN_LEFT )
     942             :         {
     943           0 :             if ( rPos.X() > pThis->mnDX-DOCK_LINEOFFSET )
     944           0 :                 return DOCK_LINEHSIZE | DOCK_LINERIGHT;
     945             :         }
     946           0 :         else if ( eAlign == WINDOWALIGN_TOP )
     947             :         {
     948           0 :             if ( rPos.Y() > pThis->mnDY-DOCK_LINEOFFSET )
     949           0 :                 return DOCK_LINEVSIZE | DOCK_LINEBOTTOM;
     950             :         }
     951           0 :         else if ( eAlign == WINDOWALIGN_RIGHT )
     952             :         {
     953           0 :             if ( rPos.X() < DOCK_LINEOFFSET )
     954           0 :                 return DOCK_LINEHSIZE | DOCK_LINELEFT;
     955             :         }
     956           0 :         else if ( eAlign == WINDOWALIGN_BOTTOM )
     957             :         {
     958           0 :             if ( rPos.Y() < DOCK_LINEOFFSET )
     959           0 :                 return DOCK_LINEVSIZE | DOCK_LINETOP;
     960             :         }
     961             :     }
     962             : 
     963           0 :     return 0;
     964             : }
     965             : 
     966           0 : void ToolBox::ImplLineSizing( ToolBox* pThis, const Point& rPos, Rectangle& rRect,
     967             :                      sal_uInt16 nLineMode )
     968             : {
     969             :     bool    mbHorz;
     970             :     long    nOneLineSize;
     971             :     long    nCurSize;
     972             :     long    nMaxSize;
     973             :     long    nSize;
     974           0 :     Size    aSize;
     975             : 
     976           0 :     if ( nLineMode & DOCK_LINERIGHT )
     977             :     {
     978           0 :         nCurSize = rPos.X() - rRect.Left();
     979           0 :         mbHorz = false;
     980             :     }
     981           0 :     else if ( nLineMode & DOCK_LINEBOTTOM )
     982             :     {
     983           0 :         nCurSize = rPos.Y() - rRect.Top();
     984           0 :         mbHorz = true;
     985             :     }
     986           0 :     else if ( nLineMode & DOCK_LINELEFT )
     987             :     {
     988           0 :         nCurSize = rRect.Right() - rPos.X();
     989           0 :         mbHorz = false;
     990             :     }
     991           0 :     else if ( nLineMode & DOCK_LINETOP )
     992             :     {
     993           0 :         nCurSize = rRect.Bottom() - rPos.Y();
     994           0 :         mbHorz = true;
     995             :     }
     996             :     else {
     997             :         OSL_FAIL( "ImplLineSizing: Trailing else" );
     998           0 :         nCurSize = 0;
     999           0 :         mbHorz = false;
    1000             :     }
    1001             : 
    1002           0 :     Size    aWinSize = pThis->GetSizePixel();
    1003           0 :     sal_uInt16  nMaxLines = (pThis->mnLines > pThis->mnCurLines) ? pThis->mnLines : pThis->mnCurLines;
    1004           0 :     if ( nMaxLines > TB_MAXLINES )
    1005           0 :         nMaxLines = TB_MAXLINES;
    1006           0 :     if ( mbHorz )
    1007             :     {
    1008           0 :         nOneLineSize = ImplCalcSize( pThis, 1 ).Height();
    1009           0 :         nMaxSize = pThis->maOutDockRect.GetHeight() - 20;
    1010           0 :         if ( nMaxSize < aWinSize.Height() )
    1011           0 :             nMaxSize = aWinSize.Height();
    1012             :     }
    1013             :     else
    1014             :     {
    1015           0 :         nOneLineSize = ImplCalcSize( pThis, 1 ).Width();
    1016           0 :         nMaxSize = pThis->maOutDockRect.GetWidth() - 20;
    1017           0 :         if ( nMaxSize < aWinSize.Width() )
    1018           0 :             nMaxSize = aWinSize.Width();
    1019             :     }
    1020             : 
    1021           0 :     sal_uInt16 i = 1;
    1022           0 :     if ( nCurSize <= nOneLineSize )
    1023           0 :         nSize = nOneLineSize;
    1024             :     else
    1025             :     {
    1026           0 :         nSize = 0;
    1027           0 :         while ( (nSize < nCurSize) && (i < nMaxLines) )
    1028             :         {
    1029           0 :             i++;
    1030           0 :             aSize = ImplCalcSize( pThis, i );
    1031           0 :             if ( mbHorz )
    1032           0 :                 nSize = aSize.Height();
    1033             :             else
    1034           0 :                 nSize = aSize.Width();
    1035           0 :             if ( nSize > nMaxSize )
    1036             :             {
    1037           0 :                 i--;
    1038           0 :                 aSize = ImplCalcSize( pThis, i );
    1039           0 :                 if ( mbHorz )
    1040           0 :                     nSize = aSize.Height();
    1041             :                 else
    1042           0 :                     nSize = aSize.Width();
    1043           0 :                 break;
    1044             :             }
    1045             :         }
    1046             :     }
    1047             : 
    1048           0 :     if ( nLineMode & DOCK_LINERIGHT )
    1049           0 :         rRect.Right() = rRect.Left()+nSize-1;
    1050           0 :     else if ( nLineMode & DOCK_LINEBOTTOM )
    1051           0 :         rRect.Bottom() = rRect.Top()+nSize-1;
    1052           0 :     else if ( nLineMode & DOCK_LINELEFT )
    1053           0 :         rRect.Left() = rRect.Right()-nSize;
    1054             :     else
    1055           0 :         rRect.Top() = rRect.Bottom()-nSize;
    1056             : 
    1057           0 :     pThis->mnDockLines = i;
    1058           0 : }
    1059             : 
    1060           0 : sal_uInt16 ToolBox::ImplFindItemPos( ToolBox* pBox, const Point& rPos )
    1061             : {
    1062           0 :     sal_uInt16  nPos = 0;
    1063           0 :     long    nLast = 0;
    1064           0 :     Point   aPos = rPos;
    1065           0 :     Size    aSize( pBox->mnDX, pBox->mnDY );
    1066             : 
    1067           0 :     if ( aPos.X() > aSize.Width()-TB_BORDER_OFFSET1 )
    1068           0 :         aPos.X() = aSize.Width()-TB_BORDER_OFFSET1;
    1069           0 :     if ( aPos.Y() > aSize.Height()-TB_BORDER_OFFSET1 )
    1070           0 :         aPos.Y() = aSize.Height()-TB_BORDER_OFFSET1;
    1071             : 
    1072             :     // Item suchen, das geklickt wurde
    1073           0 :     std::vector< ImplToolItem >::const_iterator it = pBox->mpData->m_aItems.begin();
    1074           0 :     while ( it != pBox->mpData->m_aItems.end() )
    1075             :     {
    1076           0 :         if ( it->mbVisible )
    1077             :         {
    1078           0 :             if ( nLast || !it->maRect.IsEmpty() )
    1079             :             {
    1080           0 :                 if ( pBox->mbHorz )
    1081             :                 {
    1082           0 :                     if ( nLast &&
    1083           0 :                          ((nLast < it->maRect.Top()) || it->maRect.IsEmpty()) )
    1084           0 :                         return nPos;
    1085             : 
    1086           0 :                     if ( aPos.Y() <= it->maRect.Bottom() )
    1087             :                     {
    1088           0 :                         if ( aPos.X() < it->maRect.Left() )
    1089           0 :                             return nPos;
    1090           0 :                         else if ( aPos.X() < it->maRect.Right() )
    1091           0 :                             return nPos+1;
    1092           0 :                         else if ( !nLast )
    1093           0 :                             nLast = it->maRect.Bottom();
    1094             :                     }
    1095             :                 }
    1096             :                 else
    1097             :                 {
    1098           0 :                     if ( nLast &&
    1099           0 :                          ((nLast < it->maRect.Left()) || it->maRect.IsEmpty()) )
    1100           0 :                         return nPos;
    1101             : 
    1102           0 :                     if ( aPos.X() <= it->maRect.Right() )
    1103             :                     {
    1104           0 :                         if ( aPos.Y() < it->maRect.Top() )
    1105           0 :                             return nPos;
    1106           0 :                         else if ( aPos.Y() < it->maRect.Bottom() )
    1107           0 :                             return nPos+1;
    1108           0 :                         else if ( !nLast )
    1109           0 :                             nLast = it->maRect.Right();
    1110             :                     }
    1111             :                 }
    1112             :             }
    1113             :         }
    1114             : 
    1115           0 :         nPos++;
    1116           0 :         ++it;
    1117             :     }
    1118             : 
    1119           0 :     return nPos;
    1120             : }
    1121             : 
    1122        1909 : ImplTBDragMgr::ImplTBDragMgr()
    1123           0 :     : mpBoxList(new ImplTBList())
    1124             :     , mpDragBox(NULL)
    1125             :     , mnMinWidth(0)
    1126             :     , mnMaxWidth(0)
    1127             :     , mnLineMode(0)
    1128             :     , mnStartLines(0)
    1129             :     , mpCustomizeData(NULL)
    1130             :     , mbResizeMode(false)
    1131        1909 :     , mbShowDragRect(false)
    1132             : {
    1133        1909 :     maAccel.InsertItem( KEY_RETURN, KeyCode( KEY_RETURN ) );
    1134        1909 :     maAccel.InsertItem( KEY_ESCAPE, KeyCode( KEY_ESCAPE ) );
    1135        1909 :     maAccel.SetSelectHdl( LINK( this, ImplTBDragMgr, SelectHdl ) );
    1136        1909 : }
    1137             : 
    1138        3804 : ImplTBDragMgr::~ImplTBDragMgr()
    1139             : {
    1140        1902 :     delete mpBoxList;
    1141        1902 : }
    1142             : 
    1143           0 : ToolBox* ImplTBDragMgr::FindToolBox( const Rectangle& rRect )
    1144             : {
    1145           0 :     for ( size_t i = 0, n = mpBoxList->size(); i < n; ++i )
    1146             :     {
    1147           0 :         ToolBox* pBox = (*mpBoxList)[ i ];
    1148             :         /*
    1149             :          *  FIXME: since we can have multiple frames now we cannot
    1150             :          *  find the drag target by its position alone.
    1151             :          *  As long as the toolbar config dialogue is not a system window
    1152             :          *  this works in one frame only anyway. If the dialogue
    1153             :          *  changes to a system window, we need a new implementation here
    1154             :          */
    1155           0 :         if (  pBox->IsReallyVisible()
    1156           0 :            && pBox->ImplGetWindowImpl()->mpFrame == mpDragBox->ImplGetWindowImpl()->mpFrame
    1157             :         ) {
    1158           0 :             if ( !pBox->ImplIsFloatingMode() )
    1159             :             {
    1160           0 :                 Point aPos = pBox->GetPosPixel();
    1161           0 :                 aPos = pBox->GetParent()->OutputToScreenPixel( aPos );
    1162           0 :                 Rectangle aTempRect( aPos, pBox->GetSizePixel() );
    1163           0 :                 if ( aTempRect.IsOver( rRect ) )
    1164           0 :                     return pBox;
    1165             :             }
    1166             :         }
    1167             :     }
    1168             : 
    1169           0 :     return NULL;
    1170             : }
    1171             : 
    1172           0 : void ImplTBDragMgr::StartDragging( ToolBox* pToolBox,
    1173             :                                    const Point& rPos, const Rectangle& rRect,
    1174             :                                    sal_uInt16 nDragLineMode, bool bResizeItem,
    1175             :                                    void* pData )
    1176             : {
    1177           0 :     mpDragBox = pToolBox;
    1178           0 :     pToolBox->CaptureMouse();
    1179           0 :     pToolBox->mbDragging = true;
    1180           0 :     Application::InsertAccel( &maAccel );
    1181             : 
    1182           0 :     if ( nDragLineMode )
    1183             :     {
    1184           0 :         mnLineMode = nDragLineMode;
    1185           0 :         mnStartLines = pToolBox->mnDockLines;
    1186             :     }
    1187             :     else
    1188             :     {
    1189           0 :         mpCustomizeData = pData;
    1190           0 :         mbResizeMode = bResizeItem;
    1191           0 :         pToolBox->Activate();
    1192           0 :         pToolBox->mnCurItemId = pToolBox->mnConfigItem;
    1193           0 :         pToolBox->Highlight();
    1194           0 :         pToolBox->mnCurItemId = 0;
    1195           0 :         if ( mbResizeMode )
    1196             :         {
    1197           0 :             if ( rRect.GetWidth() < TB_MIN_WIN_WIDTH )
    1198           0 :                 mnMinWidth = rRect.GetWidth();
    1199             :             else
    1200           0 :                 mnMinWidth = TB_MIN_WIN_WIDTH;
    1201           0 :             mnMaxWidth = pToolBox->GetSizePixel().Width()-rRect.Left()-
    1202           0 :                          TB_SPIN_SIZE-TB_BORDER_OFFSET1-(TB_SPIN_OFFSET*2);
    1203             :         }
    1204             :     }
    1205             : 
    1206             :     // MouseOffset berechnen
    1207           0 :     maMouseOff.X() = rRect.Left() - rPos.X();
    1208           0 :     maMouseOff.Y() = rRect.Top() - rPos.Y();
    1209           0 :     maRect = rRect;
    1210           0 :     maStartRect = rRect;
    1211           0 :     mbShowDragRect = true;
    1212           0 :     pToolBox->ShowTracking( maRect );
    1213           0 : }
    1214             : 
    1215           0 : void ImplTBDragMgr::Dragging( const Point& rPos )
    1216             : {
    1217           0 :     if ( mnLineMode )
    1218             :     {
    1219           0 :         ToolBox::ImplLineSizing( mpDragBox, rPos, maRect, mnLineMode );
    1220           0 :         Point aOff = mpDragBox->OutputToScreenPixel( Point() );
    1221           0 :         maRect.Move( aOff.X(), aOff.Y() );
    1222           0 :         mpDragBox->Docking( rPos, maRect );
    1223           0 :         maRect.Move( -aOff.X(), -aOff.Y() );
    1224           0 :         mpDragBox->ShowTracking( maRect );
    1225             :     }
    1226             :     else
    1227             :     {
    1228           0 :         if ( mbResizeMode )
    1229             :         {
    1230           0 :             long nXOff = rPos.X()-maStartRect.Left();
    1231           0 :             nXOff += maMouseOff.X()+(maStartRect.Right()-maStartRect.Left());
    1232           0 :             if ( nXOff < mnMinWidth )
    1233           0 :                 nXOff = mnMinWidth;
    1234           0 :             if ( nXOff > mnMaxWidth )
    1235           0 :                 nXOff = mnMaxWidth;
    1236           0 :             maRect.Right() = maStartRect.Left()+nXOff;
    1237             :         }
    1238             :         else
    1239             :         {
    1240           0 :             maRect.SetPos( rPos );
    1241           0 :             maRect.Move( maMouseOff.X(), maMouseOff.Y() );
    1242             :         }
    1243           0 :         mpDragBox->ShowTracking( maRect );
    1244             :     }
    1245           0 : }
    1246             : 
    1247           0 : void ImplTBDragMgr::EndDragging( bool bOK )
    1248             : {
    1249           0 :     mpDragBox->HideTracking();
    1250           0 :     mpDragBox->ReleaseMouse();
    1251           0 :     mpDragBox->mbDragging = false;
    1252           0 :     mbShowDragRect = false;
    1253           0 :     Application::RemoveAccel( &maAccel );
    1254             : 
    1255           0 :     if ( mnLineMode )
    1256             :     {
    1257           0 :         if ( !bOK )
    1258             :         {
    1259           0 :             mpDragBox->mnDockLines = mnStartLines;
    1260           0 :             mpDragBox->EndDocking( maStartRect, false );
    1261             :         }
    1262             :         else
    1263           0 :             mpDragBox->EndDocking( maRect, false );
    1264           0 :         mnLineMode = 0;
    1265           0 :         mnStartLines = 0;
    1266             :     }
    1267             :     else
    1268             :     {
    1269           0 :         sal_uInt16 nTempItem = mpDragBox->mnConfigItem;
    1270           0 :         if ( nTempItem )
    1271             :         {
    1272           0 :             mpDragBox->mnConfigItem = 0;
    1273           0 :             if ( !mbResizeMode )
    1274           0 :                 mpDragBox->Invalidate( mpDragBox->GetItemRect( nTempItem ) );
    1275             :         }
    1276             : 
    1277           0 :         if ( bOK && (maRect != maStartRect) )
    1278             :         {
    1279           0 :             if ( mbResizeMode )
    1280             :             {
    1281           0 :                 ImplToolItem* pItem = mpDragBox->ImplGetItem( nTempItem );
    1282           0 :                 Size aSize = pItem->mpWindow->GetSizePixel();
    1283           0 :                 aSize.Width() = maRect.GetWidth();
    1284           0 :                 pItem->mpWindow->SetSizePixel( aSize );
    1285             : 
    1286             :                 // re-calculate and show ToolBox
    1287           0 :                 mpDragBox->ImplInvalidate( true );
    1288             :                 mpDragBox->Customize( ToolBoxCustomizeEvent( mpDragBox, nTempItem,
    1289             :                                                              TOOLBOX_CUSTOMIZE_RESIZE,
    1290           0 :                                                              mpCustomizeData ) );
    1291             :             }
    1292             :             else
    1293             :             {
    1294           0 :                 Point aOff = mpDragBox->OutputToScreenPixel( Point() );
    1295           0 :                 Rectangle aScreenRect( maRect );
    1296           0 :                 aScreenRect.Move( aOff.X(), aOff.Y() );
    1297           0 :                 ToolBox* pDropBox = FindToolBox( aScreenRect );
    1298           0 :                 if ( pDropBox )
    1299             :                 {
    1300             :                     // Determine search position
    1301           0 :                     Point aPos;
    1302           0 :                     if ( pDropBox->mbHorz )
    1303             :                     {
    1304           0 :                         aPos.X() = aScreenRect.Left()-TB_CUSTOMIZE_OFFSET;
    1305           0 :                         aPos.Y() = aScreenRect.Center().Y();
    1306             :                     }
    1307             :                     else
    1308             :                     {
    1309           0 :                         aPos.X() = aScreenRect.Center().X();
    1310           0 :                         aPos.Y() = aScreenRect.Top()-TB_CUSTOMIZE_OFFSET;
    1311             :                     }
    1312             : 
    1313           0 :                     aPos = pDropBox->ScreenToOutputPixel( aPos );
    1314           0 :                     sal_uInt16 nPos = ToolBox::ImplFindItemPos( pDropBox, aPos );
    1315             :                     mpDragBox->Customize( ToolBoxCustomizeEvent( pDropBox, nTempItem,
    1316           0 :                                                                  nPos, mpCustomizeData ) );
    1317             :                 }
    1318             :                 else
    1319             :                 {
    1320             :                     mpDragBox->Customize( ToolBoxCustomizeEvent( NULL, nTempItem,
    1321           0 :                                                                  0, mpCustomizeData ) );
    1322             :                 }
    1323             :             }
    1324             :         }
    1325           0 :         mpCustomizeData = NULL;
    1326           0 :         mbResizeMode = false;
    1327           0 :         mpDragBox->Deactivate();
    1328             :     }
    1329             : 
    1330           0 :     mpDragBox = NULL;
    1331           0 : }
    1332             : 
    1333           0 : void ImplTBDragMgr::UpdateDragRect()
    1334             : {
    1335             :     // Only update if we're already dragging
    1336           0 :     if ( !mbShowDragRect )
    1337           0 :         return;
    1338             : 
    1339           0 :     mpDragBox->ShowTracking( maRect );
    1340             : }
    1341             : 
    1342           0 : IMPL_LINK( ImplTBDragMgr, SelectHdl, Accelerator*, pAccel )
    1343             : {
    1344           0 :     if ( pAccel->GetCurItemId() == KEY_ESCAPE )
    1345           0 :         EndDragging( false );
    1346             :     else
    1347           0 :         EndDragging( true );
    1348             : 
    1349           0 :     return (long) true;
    1350             : }
    1351             : 
    1352       11164 : void ToolBox::ImplInit( Window* pParent, WinBits nStyle )
    1353             : {
    1354             : 
    1355             :     // initialize variables
    1356       11164 :     ImplGetWindowImpl()->mbToolBox         = true;
    1357       11164 :     mpData                = new ImplToolBoxPrivateData;
    1358       11164 :     mpFloatWin        = NULL;
    1359       11164 :     mnDX              = 0;
    1360       11164 :     mnDY              = 0;
    1361       11164 :     mnMaxItemWidth    = 0;
    1362       11164 :     mnMaxItemHeight   = 0;
    1363       11164 :     mnWinHeight       = 0;
    1364       11164 :     mnLeftBorder      = 0;
    1365       11164 :     mnTopBorder       = 0;
    1366       11164 :     mnRightBorder     = 0;
    1367       11164 :     mnBottomBorder    = 0;
    1368       11164 :     mnLastResizeDY    = 0;
    1369       11164 :     mnOutStyle        = TOOLBOX_STYLE_FLAT; // force flat buttons since NWF
    1370       11164 :     mnHighItemId      = 0;
    1371       11164 :     mnCurItemId       = 0;
    1372       11164 :     mnDownItemId      = 0;
    1373       11164 :     mnCurPos          = TOOLBOX_ITEM_NOTFOUND;
    1374       11164 :     mnFocusPos        = TOOLBOX_ITEM_NOTFOUND;    // current position during keyboard access
    1375       11164 :     mnLines           = 1;
    1376       11164 :     mnCurLine         = 1;
    1377       11164 :     mnCurLines        = 1;
    1378       11164 :     mnVisLines        = 1;
    1379       11164 :     mnFloatLines      = 0;
    1380       11164 :     mnConfigItem      = 0;
    1381       11164 :     mnMouseClicks     = 0;
    1382       11164 :     mnMouseModifier   = 0;
    1383       11164 :     mbDrag            = false;
    1384       11164 :     mbSelection       = false;
    1385       11164 :     mbCommandDrag     = false;
    1386       11164 :     mbUpper           = false;
    1387       11164 :     mbLower           = false;
    1388       11164 :     mbIn              = false;
    1389       11164 :     mbCalc            = true;
    1390       11164 :     mbFormat          = false;
    1391       11164 :     mbFullPaint       = false;
    1392       11164 :     mbHorz            = true;
    1393       11164 :     mbScroll          = (nStyle & WB_SCROLL) != 0;
    1394       11164 :     mbCustomize       = false;
    1395       11164 :     mbCustomizeMode   = false;
    1396       11164 :     mbDragging        = false;
    1397       11164 :     mbMenuStrings     = false;
    1398       11164 :     mbIsShift          = false;
    1399       11164 :     mbIsKeyEvent = false;
    1400       11164 :     mbChangingHighlight = false;
    1401       11164 :     meButtonType      = BUTTON_SYMBOL;
    1402       11164 :     meAlign           = WINDOWALIGN_TOP;
    1403       11164 :     meLastStyle       = POINTER_ARROW;
    1404       11164 :     mnWinStyle        = nStyle;
    1405       11164 :     meLayoutMode      = TBX_LAYOUT_NORMAL;
    1406       11164 :     mnLastFocusItemId = 0;
    1407       11164 :     mnKeyModifier     = 0;
    1408       11164 :     mnActivateCount   = 0;
    1409             : 
    1410       11164 :     maTimer.SetTimeout( 50 );
    1411       11164 :     maTimer.SetTimeoutHdl( LINK( this, ToolBox, ImplUpdateHdl ) );
    1412             : 
    1413             :     // set timeout and handler for dropdown items
    1414       11164 :     mpData->maDropdownTimer.SetTimeout( 250 );
    1415       11164 :     mpData->maDropdownTimer.SetTimeoutHdl( LINK( this, ToolBox, ImplDropdownLongClickHdl ) );
    1416             : 
    1417       11164 :     DockingWindow::ImplInit( pParent, nStyle & ~(WB_BORDER) );
    1418             : 
    1419             :     // always set WB_TABSTOP for ToolBars !!!  if( mnWinStyle & WB_TABSTOP )
    1420             :     {
    1421             :         // dockingwindow's ImplInit removes some bits, so restore them here
    1422             :         // to allow keyboard handling for toolbars
    1423       11164 :         ImplGetWindowImpl()->mnStyle |= WB_TABSTOP|WB_NODIALOGCONTROL;
    1424       11164 :         ImplGetWindowImpl()->mnStyle &= ~WB_DIALOGCONTROL;
    1425             :     }
    1426             : 
    1427       11164 :     ImplInitSettings( true, true, true );
    1428       11164 : }
    1429             : 
    1430       11580 : void ToolBox::ImplInitSettings( bool bFont,
    1431             :                                 bool bForeground, bool bBackground )
    1432             : {
    1433       11580 :     mpData->mbNativeButtons = IsNativeControlSupported( CTRL_TOOLBAR, PART_BUTTON );
    1434             : 
    1435       11580 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
    1436             : 
    1437       11580 :     if ( bFont )
    1438             :     {
    1439       11322 :         Font aFont = rStyleSettings.GetToolFont();
    1440       11322 :         if ( IsControlFont() )
    1441           0 :             aFont.Merge( GetControlFont() );
    1442       11322 :         SetZoomedPointFont( aFont );
    1443             :     }
    1444             : 
    1445       11580 :     if ( bForeground || bFont )
    1446             :     {
    1447       11322 :         Color aColor;
    1448       11322 :         if ( IsControlForeground() )
    1449           0 :             aColor = GetControlForeground();
    1450       11322 :         else if ( Window::GetStyle() & WB_3DLOOK )
    1451        7233 :             aColor = rStyleSettings.GetButtonTextColor();
    1452             :         else
    1453        4089 :             aColor = rStyleSettings.GetWindowTextColor();
    1454       11322 :         SetTextColor( aColor );
    1455       11322 :         SetTextFillColor();
    1456             :     }
    1457             : 
    1458       11580 :     if ( bBackground )
    1459             :     {
    1460       11580 :         Color aColor;
    1461       11580 :         if ( IsControlBackground() )
    1462             :         {
    1463           0 :             aColor = GetControlBackground();
    1464           0 :             SetBackground( aColor );
    1465           0 :             SetPaintTransparent( false );
    1466           0 :             SetParentClipMode( 0 );
    1467             :         }
    1468             :         else
    1469             :         {
    1470       34998 :             if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) ||
    1471       45804 :                 ( GetAlign() == WINDOWALIGN_TOP && !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty() ) )
    1472             :             {
    1473           0 :                 SetBackground();
    1474           0 :                 SetPaintTransparent( true );
    1475           0 :                 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
    1476           0 :                 mpData->maDisplayBackground = Wallpaper( rStyleSettings.GetFaceColor() );
    1477             :             }
    1478             :             else
    1479             :             {
    1480       11580 :                 if ( Window::GetStyle() & WB_3DLOOK )
    1481        7491 :                     aColor = rStyleSettings.GetFaceColor();
    1482             :                 else
    1483        4089 :                     aColor = rStyleSettings.GetWindowColor();
    1484             : 
    1485       11580 :                 SetBackground( aColor );
    1486       11580 :                 SetPaintTransparent( false );
    1487       11580 :                 SetParentClipMode( 0 );
    1488             : 
    1489       11580 :                 ImplUpdateImageList();
    1490             :             }
    1491             :         }
    1492             :     }
    1493       11580 : }
    1494             : 
    1495         230 : void ToolBox::ImplLoadRes( const ResId& rResId )
    1496             : {
    1497         230 :     ResMgr* pMgr = rResId.GetResMgr();
    1498         230 :     if( ! pMgr )
    1499         230 :         return;
    1500             : 
    1501         230 :     DockingWindow::ImplLoadRes( rResId );
    1502             : 
    1503             :     sal_uLong              nObjMask;
    1504             : 
    1505         230 :     nObjMask = ReadLongRes();
    1506             : 
    1507         230 :     if ( nObjMask & RSC_TOOLBOX_BUTTONTYPE )
    1508           0 :         SetButtonType( (ButtonType)ReadLongRes() );
    1509             : 
    1510         230 :     if ( nObjMask & RSC_TOOLBOX_ALIGN )
    1511           0 :         SetAlign( (WindowAlign)ReadLongRes() );
    1512             : 
    1513         230 :     if ( nObjMask & RSC_TOOLBOX_LINECOUNT )
    1514         170 :         SetLineCount( sal::static_int_cast<sal_uInt16>(ReadLongRes()) );
    1515             : 
    1516         230 :     if ( nObjMask & RSC_TOOLBOX_CUSTOMIZE )
    1517             :     {
    1518           0 :         bool bCust = ReadShortRes();
    1519           0 :         EnableCustomize( bCust );
    1520             :     }
    1521             : 
    1522         230 :     if ( nObjMask & RSC_TOOLBOX_MENUSTRINGS )
    1523             :     {
    1524           0 :         bool bCust = ReadShortRes();
    1525           0 :         EnableMenuStrings( bCust );
    1526             :     }
    1527             : 
    1528         230 :     if ( nObjMask & RSC_TOOLBOX_FLOATLINES )
    1529           0 :         SetFloatingLines( ReadShortRes() );
    1530             : 
    1531         230 :     if ( nObjMask & RSC_TOOLBOX_ITEMIMAGELIST )
    1532             :     {
    1533          60 :         maImageList = ImageList( ResId( (RSHEADER_TYPE*)GetClassRes(), *pMgr ) );
    1534          60 :         IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
    1535             :     }
    1536             : 
    1537         230 :     if ( nObjMask & RSC_TOOLBOX_ITEMLIST )
    1538             :     {
    1539         230 :         sal_uLong nEle = ReadLongRes();
    1540             : 
    1541             :         // insert item
    1542        4405 :         for ( sal_uLong i = 0; i < nEle; i++ )
    1543             :         {
    1544        4175 :             InsertItem( ResId( (RSHEADER_TYPE *)GetClassRes(), *pMgr ) );
    1545        4175 :             IncrementRes( GetObjSizeRes( (RSHEADER_TYPE *)GetClassRes() ) );
    1546             :         }
    1547             :     }
    1548             : }
    1549             : 
    1550       10934 : ToolBox::ToolBox( Window* pParent, WinBits nStyle ) :
    1551       10934 :     DockingWindow( WINDOW_TOOLBOX )
    1552             : {
    1553       10934 :     ImplInit( pParent, nStyle );
    1554       10934 : }
    1555             : 
    1556         230 : ToolBox::ToolBox( Window* pParent, const ResId& rResId ) :
    1557         230 :     DockingWindow( WINDOW_TOOLBOX )
    1558             : {
    1559             :     SAL_INFO( "vcl.window", "vcl: ToolBox::ToolBox( Window* pParent, const ResId& rResId )" );
    1560             : 
    1561         230 :     rResId.SetRT( RSC_TOOLBOX );
    1562         230 :     WinBits nStyle = ImplInitRes( rResId );
    1563         230 :     ImplInit( pParent, nStyle );
    1564         230 :     ImplLoadRes( rResId );
    1565             : 
    1566             :     // calculate size of floating windows and switch if the
    1567             :     // toolbox is initially in floating mode
    1568         230 :     if ( ImplIsFloatingMode() )
    1569           0 :         mbHorz = true;
    1570             :     else
    1571         230 :         Resize();
    1572             : 
    1573         230 :     if ( !(nStyle & WB_HIDE) )
    1574          77 :         Show();
    1575         230 : }
    1576             : 
    1577       28867 : ToolBox::~ToolBox()
    1578             : {
    1579             :     // custom menu event still running?
    1580       11134 :     if( mpData->mnEventId )
    1581           0 :         Application::RemoveUserEvent( mpData->mnEventId );
    1582             : 
    1583             :     // #103005# make sure our activate/deactivate balance is right
    1584       22268 :     while( mnActivateCount > 0 )
    1585           0 :         Deactivate();
    1586             : 
    1587             :     // terminate popupmode if the floating window is
    1588             :     // still connected
    1589       11134 :     if ( mpFloatWin )
    1590           0 :         mpFloatWin->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL );
    1591             : 
    1592             :     // delete private data
    1593       11134 :     delete mpData;
    1594             : 
    1595             :     // remove the lists when there are no more toolbox references to
    1596             :     // the lists
    1597       11134 :     ImplSVData* pSVData = ImplGetSVData();
    1598       11134 :     if ( pSVData->maCtrlData.mpTBDragMgr )
    1599             :     {
    1600             :         // remove if in TBDrag-Manager
    1601       10863 :         if ( mbCustomize )
    1602        6089 :             pSVData->maCtrlData.mpTBDragMgr->erase( this );
    1603             : 
    1604       10863 :         if ( !pSVData->maCtrlData.mpTBDragMgr->size() )
    1605             :         {
    1606        1902 :             delete pSVData->maCtrlData.mpTBDragMgr;
    1607        1902 :             pSVData->maCtrlData.mpTBDragMgr = NULL;
    1608             :         }
    1609             :     }
    1610       17733 : }
    1611             : 
    1612      461306 : ImplToolItem* ToolBox::ImplGetItem( sal_uInt16 nItemId ) const
    1613             : {
    1614      461306 :     std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
    1615     8571367 :     while ( it != mpData->m_aItems.end() )
    1616             :     {
    1617     8109723 :         if ( it->mnId == nItemId )
    1618      460968 :             return &(*it);
    1619     7648755 :         ++it;
    1620             :     }
    1621             : 
    1622         338 :     return NULL;
    1623             : }
    1624             : 
    1625       87138 : static void ImplAddButtonBorder( long &rWidth, long& rHeight, bool bNativeButtons )
    1626             : {
    1627       87138 :     rWidth += SMALLBUTTON_HSIZE;
    1628       87138 :     rHeight += SMALLBUTTON_VSIZE;
    1629             : 
    1630       87138 :     if( bNativeButtons )
    1631             :     {
    1632             :         // give more border space for rounded buttons
    1633           0 :         rWidth += 2;
    1634           0 :         rHeight += 4;
    1635             :     }
    1636       87138 : }
    1637             : 
    1638       34913 : bool ToolBox::ImplCalcItem()
    1639             : {
    1640             : 
    1641             :     // recalc required ?
    1642       34913 :     if ( !mbCalc )
    1643       23411 :         return false;
    1644             : 
    1645       11502 :     ImplDisableFlatButtons();
    1646             : 
    1647             :     long            nDefWidth;
    1648             :     long            nDefHeight;
    1649       11502 :     long            nMaxWidth = 0;
    1650       11502 :     long            nMaxHeight = 0;
    1651       11502 :     long            nMinWidth   = 6;
    1652       11502 :     long            nMinHeight  = 6;
    1653       11502 :     long            nDropDownArrowWidth = TB_DROPDOWNARROWWIDTH;
    1654             : 
    1655             :     // set defaults if image or text is needed but empty
    1656       11502 :     nDefWidth       = GetDefaultImageSize().Width() * GetDPIScaleFactor();
    1657       11502 :     nDefHeight      = GetDefaultImageSize().Height() * GetDPIScaleFactor();
    1658             : 
    1659       11502 :     mnWinHeight = 0;
    1660             :     // determine minimum size necessary in NWF
    1661             :     {
    1662       11502 :         Rectangle aRect( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
    1663       11502 :         Rectangle aReg( aRect );
    1664       11502 :         ImplControlValue aVal;
    1665       11502 :         Rectangle aNativeBounds, aNativeContent;
    1666       11502 :         if( IsNativeControlSupported( CTRL_TOOLBAR, PART_BUTTON ) )
    1667             :         {
    1668           0 :             if( GetNativeControlRegion( CTRL_TOOLBAR, PART_BUTTON,
    1669             :                                         aReg,
    1670             :                                         CTRL_STATE_ENABLED | CTRL_STATE_ROLLOVER,
    1671             :                                         aVal, OUString(),
    1672           0 :                                         aNativeBounds, aNativeContent ) )
    1673             :             {
    1674           0 :                 aRect = aNativeBounds;
    1675           0 :                 if( aRect.GetWidth() > nMinWidth )
    1676           0 :                     nMinWidth = aRect.GetWidth();
    1677           0 :                 if( aRect.GetHeight() > nMinHeight )
    1678           0 :                     nMinHeight = aRect.GetHeight();
    1679           0 :                 if( nDropDownArrowWidth < nMinWidth )
    1680           0 :                     nDropDownArrowWidth = nMinWidth;
    1681           0 :                 if( nMinWidth > mpData->mnMenuButtonWidth )
    1682           0 :                     mpData->mnMenuButtonWidth = nMinWidth;
    1683           0 :                 else if( nMinWidth < TB_MENUBUTTON_SIZE )
    1684           0 :                     mpData->mnMenuButtonWidth = TB_MENUBUTTON_SIZE;
    1685             :             }
    1686             :         }
    1687             : 
    1688             :         // also calculate the area for comboboxes, drop down list boxes and spinfields
    1689             :         // as these are often inserted into toolboxes; set mnWinHeight to the
    1690             :         // greater of those values to prevent toolbar flickering (#i103385#)
    1691       11502 :         aRect = Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
    1692       11502 :         aReg = aRect;
    1693       23004 :         if( GetNativeControlRegion( CTRL_COMBOBOX, PART_ENTIRE_CONTROL,
    1694             :                                     aReg,
    1695             :                                     CTRL_STATE_ENABLED | CTRL_STATE_ROLLOVER,
    1696             :                                     aVal, OUString(),
    1697       23004 :                                     aNativeBounds, aNativeContent ) )
    1698             :         {
    1699           0 :             aRect = aNativeBounds;
    1700           0 :             if( aRect.GetHeight() > mnWinHeight )
    1701           0 :                 mnWinHeight = aRect.GetHeight();
    1702             :         }
    1703       11502 :         aRect = Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
    1704       11502 :         aReg = aRect;
    1705       23004 :         if( GetNativeControlRegion( CTRL_LISTBOX, PART_ENTIRE_CONTROL,
    1706             :                                     aReg,
    1707             :                                     CTRL_STATE_ENABLED | CTRL_STATE_ROLLOVER,
    1708             :                                     aVal, OUString(),
    1709       23004 :                                     aNativeBounds, aNativeContent ) )
    1710             :         {
    1711           0 :             aRect = aNativeBounds;
    1712           0 :             if( aRect.GetHeight() > mnWinHeight )
    1713           0 :                 mnWinHeight = aRect.GetHeight();
    1714             :         }
    1715       11502 :         aRect = Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
    1716       11502 :         aReg = aRect;
    1717       23004 :         if( GetNativeControlRegion( CTRL_SPINBOX, PART_ENTIRE_CONTROL,
    1718             :                                     aReg,
    1719             :                                     CTRL_STATE_ENABLED | CTRL_STATE_ROLLOVER,
    1720             :                                     aVal, OUString(),
    1721       23004 :                                     aNativeBounds, aNativeContent ) )
    1722             :         {
    1723           0 :             aRect = aNativeBounds;
    1724           0 :             if( aRect.GetHeight() > mnWinHeight )
    1725           0 :                 mnWinHeight = aRect.GetHeight();
    1726       11502 :         }
    1727             :     }
    1728             : 
    1729       11502 :     if ( ! mpData->m_aItems.empty() )
    1730             :     {
    1731        8380 :         std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
    1732      109959 :         while ( it != mpData->m_aItems.end() )
    1733             :         {
    1734             :             bool bImage;
    1735             :             bool bText;
    1736             : 
    1737       93199 :             it->mbVisibleText = false;  // indicates if text will definitely be drawn, influences dropdown pos
    1738             : 
    1739       93199 :             if ( it->meType == TOOLBOXITEM_BUTTON )
    1740             :             {
    1741             :                 // check if image and/or text exists
    1742       77437 :                 if ( !(it->maImage) )
    1743       18197 :                     bImage = false;
    1744             :                 else
    1745       59240 :                     bImage = true;
    1746       77437 :                 if ( it->maText.isEmpty() )
    1747        7160 :                     bText = false;
    1748             :                 else
    1749       70277 :                     bText = true;
    1750       77437 :                 ButtonType tmpButtonType = determineButtonType( &(*it), meButtonType ); // default to toolbox setting
    1751       77437 :                 if ( bImage || bText )
    1752             :                 {
    1753             : 
    1754       76618 :                     it->mbEmptyBtn = false;
    1755             : 
    1756      153236 :                     if ( tmpButtonType == BUTTON_SYMBOL )
    1757             :                     {
    1758             :                         // we're drawing images only
    1759       76618 :                         if ( bImage || !bText )
    1760             :                         {
    1761       59240 :                             it->maItemSize = it->maImage.GetSizePixel();
    1762             :                         }
    1763             :                         else
    1764             :                         {
    1765       34756 :                             it->maItemSize = Size( GetCtrlTextWidth( it->maText )+TB_TEXTOFFSET,
    1766       34756 :                                                    GetTextHeight() );
    1767       17378 :                             it->mbVisibleText = true;
    1768             :                         }
    1769             :                     }
    1770           0 :                     else if ( tmpButtonType == BUTTON_TEXT )
    1771             :                     {
    1772             :                         // we're drawing text only
    1773           0 :                         if ( bText || !bImage )
    1774             :                         {
    1775           0 :                             it->maItemSize = Size( GetCtrlTextWidth( it->maText )+TB_TEXTOFFSET,
    1776           0 :                                                    GetTextHeight() );
    1777           0 :                             it->mbVisibleText = true;
    1778             :                         }
    1779             :                         else
    1780             :                         {
    1781           0 :                             it->maItemSize = it->maImage.GetSizePixel();
    1782             :                         }
    1783             :                     }
    1784             :                     else
    1785             :                     {
    1786             :                         // we're drawing images and text
    1787           0 :                         it->maItemSize.Width() = bText ? GetCtrlTextWidth( it->maText )+TB_TEXTOFFSET : 0;
    1788           0 :                         it->maItemSize.Height() = bText ? GetTextHeight() : 0;
    1789             : 
    1790             :                         // leave space between image and text
    1791           0 :                         if( bText )
    1792           0 :                             it->maItemSize.Width() += TB_IMAGETEXTOFFSET;
    1793             : 
    1794             :                         // image and text side by side
    1795           0 :                         it->maItemSize.Width() += it->maImage.GetSizePixel().Width();
    1796           0 :                         if ( it->maImage.GetSizePixel().Height() > it->maItemSize.Height() )
    1797           0 :                             it->maItemSize.Height() = it->maImage.GetSizePixel().Height();
    1798             : 
    1799           0 :                         it->mbVisibleText = bText;
    1800             :                     }
    1801             :                 }
    1802             :                 else
    1803             :                 {   // no image and no text
    1804         819 :                     it->maItemSize = Size( nDefWidth, nDefHeight );
    1805         819 :                     it->mbEmptyBtn = true;
    1806             :                 }
    1807             : 
    1808             :                 // save the content size
    1809       77437 :                 it->maContentSize = it->maItemSize;
    1810             : 
    1811             :                 // if required, take window height into consideration
    1812       77437 :                 if ( it->mpWindow )
    1813             :                 {
    1814        5120 :                     long nHeight = it->mpWindow->GetSizePixel().Height();
    1815        5120 :                     if ( nHeight > mnWinHeight )
    1816        2889 :                         mnWinHeight = nHeight;
    1817             :                 }
    1818             : 
    1819             :                 // add in drop down arrow
    1820       77437 :                 if( it->mnBits & TIB_DROPDOWN )
    1821             :                 {
    1822        8466 :                     it->maItemSize.Width() += nDropDownArrowWidth;
    1823        8466 :                     it->mnDropDownArrowWidth = nDropDownArrowWidth;
    1824             :                 }
    1825             : 
    1826             :                 // text items will be rotated in vertical mode
    1827             :                 // -> swap width and height
    1828       77437 :                 if( it->mbVisibleText && !mbHorz )
    1829             :                 {
    1830           0 :                     long tmp = it->maItemSize.Width();
    1831           0 :                     it->maItemSize.Width() = it->maItemSize.Height();
    1832           0 :                     it->maItemSize.Height() = tmp;
    1833             : 
    1834           0 :                     tmp = it->maContentSize.Width();
    1835           0 :                     it->maContentSize.Width() = it->maContentSize.Height();
    1836           0 :                     it->maContentSize.Height() = tmp;
    1837             :                 }
    1838             :             }
    1839       15762 :             else if ( it->meType == TOOLBOXITEM_SPACE )
    1840             :             {
    1841          17 :                 it->maItemSize = Size( nDefWidth, nDefHeight );
    1842          17 :                 it->maContentSize = it->maItemSize;
    1843             :             }
    1844             : 
    1845       93199 :             if ( it->meType == TOOLBOXITEM_BUTTON || it->meType == TOOLBOXITEM_SPACE )
    1846             :             {
    1847             :                 // add borders
    1848       77454 :                 ImplAddButtonBorder( it->maItemSize.Width(), it->maItemSize.Height(), mpData->mbNativeButtons );
    1849             : 
    1850       77454 :                 if( it->meType == TOOLBOXITEM_BUTTON )
    1851             :                 {
    1852       77437 :                     long nMinW = std::max(nMinWidth, it->maMinimalItemSize.Width());
    1853       77437 :                     long nMinH = std::max(nMinHeight, it->maMinimalItemSize.Height());
    1854             : 
    1855       77437 :                     long nGrowContentWidth = 0;
    1856       77437 :                     long nGrowContentHeight = 0;
    1857             : 
    1858       77437 :                     if( it->maItemSize.Width() < nMinW )
    1859             :                     {
    1860           0 :                         nGrowContentWidth = nMinW - it->maItemSize.Width();
    1861           0 :                         it->maItemSize.Width() = nMinW;
    1862             :                     }
    1863       77437 :                     if( it->maItemSize.Height() < nMinH )
    1864             :                     {
    1865           0 :                         nGrowContentHeight = nMinH - it->maItemSize.Height();
    1866           0 :                         it->maItemSize.Height() = nMinH;
    1867             :                     }
    1868             : 
    1869             :                     // grow the content size by the additional available space
    1870       77437 :                     it->maContentSize.Width() += nGrowContentWidth;
    1871       77437 :                     it->maContentSize.Height() += nGrowContentHeight;
    1872             :                 }
    1873             : 
    1874             :                 // keep track of max item size
    1875       77454 :                 if ( it->maItemSize.Width() > nMaxWidth )
    1876       11967 :                     nMaxWidth = it->maItemSize.Width();
    1877       77454 :                 if ( it->maItemSize.Height() > nMaxHeight )
    1878        8555 :                     nMaxHeight = it->maItemSize.Height();
    1879             :             }
    1880             : 
    1881       93199 :             ++it;
    1882             :         }
    1883             :     }
    1884             :     else
    1885             :     {
    1886        3122 :         nMaxWidth  = nDefWidth;
    1887        3122 :         nMaxHeight = nDefHeight;
    1888             : 
    1889        3122 :         ImplAddButtonBorder( nMaxWidth, nMaxHeight, mpData->mbNativeButtons );
    1890             :     }
    1891             : 
    1892       11502 :     if( !ImplIsFloatingMode() && GetToolboxButtonSize() != TOOLBOX_BUTTONSIZE_DONTCARE )
    1893             :     {
    1894             :         // make sure all vertical toolbars have the same width and horizontal have the same height
    1895             :         // this depends on the used button sizes
    1896             :         // as this is used for alignement of multiple toolbars
    1897             :         // it is only required for docked toolbars
    1898             : 
    1899        6562 :         long nFixedWidth = nDefWidth+nDropDownArrowWidth;
    1900        6562 :         long nFixedHeight = nDefHeight;
    1901        6562 :         ImplAddButtonBorder( nFixedWidth, nFixedHeight, mpData->mbNativeButtons );
    1902             : 
    1903        6562 :         if( mbHorz )
    1904        6562 :             nMaxHeight = nFixedHeight;
    1905             :         else
    1906           0 :             nMaxWidth = nFixedWidth;
    1907             :     }
    1908             : 
    1909       11502 :     mbCalc = false;
    1910       11502 :     mbFormat = true;
    1911             : 
    1912             :     // do we have to recalc the sizes ?
    1913       11502 :     if ( (nMaxWidth != mnMaxItemWidth) || (nMaxHeight != mnMaxItemHeight) )
    1914             :     {
    1915       10967 :         mnMaxItemWidth  = nMaxWidth;
    1916       10967 :         mnMaxItemHeight = nMaxHeight;
    1917             : 
    1918       10967 :         return true;
    1919             :     }
    1920             :     else
    1921         535 :         return false;
    1922             : }
    1923             : 
    1924       31244 : sal_uInt16 ToolBox::ImplCalcBreaks( long nWidth, long* pMaxLineWidth, bool bCalcHorz )
    1925             : {
    1926       31244 :     sal_uLong           nLineStart = 0;
    1927       31244 :     sal_uLong           nGroupStart = 0;
    1928       31244 :     long            nLineWidth = 0;
    1929             :     long            nCurWidth;
    1930       31244 :     long            nLastGroupLineWidth = 0;
    1931       31244 :     long            nMaxLineWidth = 0;
    1932       31244 :     sal_uInt16          nLines = 1;
    1933             :     bool            bWindow;
    1934       31244 :     bool            bBreak = false;
    1935       31244 :     long            nWidthTotal = nWidth;
    1936       31244 :     long nMenuWidth = 0;
    1937             : 
    1938             :     // when docked the menubutton will be in the first line
    1939       31244 :     if( IsMenuEnabled() && !ImplIsFloatingMode() )
    1940       22140 :         nMenuWidth = mpData->maMenubuttonItem.maItemSize.Width();
    1941             : 
    1942             :     // we need to know which item is the last visible one to be able to add
    1943             :     // the menu width in case we are unable to show all the items
    1944       31244 :     std::vector< ImplToolItem >::iterator it, lastVisible;
    1945      403616 :     for ( it = mpData->m_aItems.begin(); it != mpData->m_aItems.end(); ++it )
    1946             :     {
    1947      372372 :         if ( it->mbVisible )
    1948      301087 :             lastVisible = it;
    1949             :     }
    1950             : 
    1951       31244 :     it = mpData->m_aItems.begin();
    1952      434860 :     while ( it != mpData->m_aItems.end() )
    1953             :     {
    1954      372372 :         it->mbBreak = bBreak;
    1955      372372 :         bBreak = false;
    1956             : 
    1957      372372 :         if ( it->mbVisible )
    1958             :         {
    1959      301087 :             bWindow     = false;
    1960      301087 :             bBreak      = false;
    1961      301087 :             nCurWidth   = 0;
    1962             : 
    1963      301087 :             if ( it->meType == TOOLBOXITEM_BUTTON || it->meType == TOOLBOXITEM_SPACE )
    1964             :             {
    1965      229660 :                 if ( bCalcHorz )
    1966      229660 :                     nCurWidth = it->maItemSize.Width();
    1967             :                 else
    1968           0 :                     nCurWidth = it->maItemSize.Height();
    1969             : 
    1970      229660 :                 if ( it->mpWindow && bCalcHorz )
    1971             :                 {
    1972       18269 :                     long nWinItemWidth = it->mpWindow->GetSizePixel().Width();
    1973       18269 :                     if ( !mbScroll || (nWinItemWidth <= nWidthTotal) )
    1974             :                     {
    1975       18269 :                         nCurWidth = nWinItemWidth;
    1976       18269 :                         bWindow   = true;
    1977             :                     }
    1978             :                     else
    1979             :                     {
    1980           0 :                         if ( it->mbEmptyBtn )
    1981             :                         {
    1982           0 :                             nCurWidth = 0;
    1983             :                         }
    1984             :                     }
    1985             :                 }
    1986             : 
    1987             :                 // in case we are able to show all the items, we do not want
    1988             :                 // to show the toolbar's menu; otherwise yes
    1989      459477 :                 if ( ( ( it == lastVisible ) && (nLineWidth+nCurWidth > nWidthTotal) && mbScroll ) ||
    1990      439606 :                      ( ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) && mbScroll ) )
    1991         170 :                     bBreak = true;
    1992             :             }
    1993       71427 :             else if ( it->meType == TOOLBOXITEM_SEPARATOR )
    1994             :             {
    1995       71083 :                 nCurWidth = it->mnSepSize;
    1996       71083 :                 if ( !ImplIsFloatingMode() && ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) )
    1997           0 :                     bBreak = true;
    1998             :             }
    1999             :             // treat breaks as separators, except when using old style toolbars (ie. no menu button)
    2000         344 :             else if ( (it->meType == TOOLBOXITEM_BREAK) && !IsMenuEnabled() )
    2001         340 :                 bBreak = true;
    2002             : 
    2003      301087 :             if ( bBreak )
    2004             :             {
    2005         510 :                 nLines++;
    2006             : 
    2007             :                 // Add break before the entire group or take group apart?
    2008         510 :                 if ( (it->meType == TOOLBOXITEM_BREAK) ||
    2009             :                      (nLineStart == nGroupStart) )
    2010             :                 {
    2011         510 :                     if ( nLineWidth > nMaxLineWidth )
    2012         339 :                         nMaxLineWidth = nLineWidth;
    2013             : 
    2014         510 :                     nLineWidth = 0;
    2015         510 :                     nLineStart = it - mpData->m_aItems.begin();
    2016         510 :                     nGroupStart = nLineStart;
    2017         510 :                     it->mbBreak = true;
    2018         510 :                     bBreak = false;
    2019             :                 }
    2020             :                 else
    2021             :                 {
    2022           0 :                     if ( nLastGroupLineWidth > nMaxLineWidth )
    2023           0 :                         nMaxLineWidth = nLastGroupLineWidth;
    2024             : 
    2025             :                     // if the break is added before the group, set it to
    2026             :                     // beginning of line and re-calculate
    2027           0 :                     nLineWidth = 0;
    2028           0 :                     nLineStart = nGroupStart;
    2029           0 :                     it = mpData->m_aItems.begin() + nGroupStart;
    2030           0 :                     continue;
    2031             :                 }
    2032             :             }
    2033             :             else
    2034             :             {
    2035      300577 :                 if( ImplIsFloatingMode() || !IsMenuEnabled() ) // no group breaking when being docked single-line
    2036             :                 {
    2037       26567 :                     if ( (it->meType != TOOLBOXITEM_BUTTON) || bWindow )
    2038             :                     {
    2039             :                         // found separator or break
    2040        8036 :                         nLastGroupLineWidth = nLineWidth;
    2041        8036 :                         nGroupStart = it - mpData->m_aItems.begin();
    2042        8036 :                         if ( !bWindow )
    2043        3932 :                             nGroupStart++;
    2044             :                     }
    2045             :                 }
    2046             :             }
    2047             : 
    2048      301087 :             nLineWidth += nCurWidth;
    2049             :         }
    2050             : 
    2051      372372 :         ++it;
    2052             :     }
    2053             : 
    2054       31244 :     if ( pMaxLineWidth )
    2055             :     {
    2056       26801 :         if ( nLineWidth > nMaxLineWidth )
    2057       16444 :             nMaxLineWidth = nLineWidth;
    2058             : 
    2059       26801 :         if( ImplIsFloatingMode() && !ImplIsInPopupMode() )
    2060             :         {
    2061             :             // leave enough space to display buttons in the decoration
    2062           0 :             long aMinWidth = 2 * GetSettings().GetStyleSettings().GetFloatTitleHeight();
    2063           0 :             if( nMaxLineWidth < aMinWidth )
    2064           0 :                 nMaxLineWidth = aMinWidth;
    2065             :         }
    2066       26801 :         *pMaxLineWidth = nMaxLineWidth;
    2067             :     }
    2068             : 
    2069       31244 :     return nLines;
    2070             : }
    2071             : 
    2072           0 : Size ToolBox::ImplGetOptimalFloatingSize()
    2073             : {
    2074           0 :     if( !ImplIsFloatingMode() )
    2075           0 :         return Size();
    2076             : 
    2077           0 :     Size aCurrentSize( mnDX, mnDY );
    2078           0 :     Size aSize1( aCurrentSize );
    2079           0 :     Size aSize2( aCurrentSize );
    2080             : 
    2081             :     // try to preserve current height
    2082             : 
    2083             :     // calc number of floating lines for current window height
    2084           0 :     sal_uInt16 nFloatLinesHeight = ImplCalcLines( this, mnDY );
    2085             :     // calc window size according to this number
    2086           0 :     aSize1 = ImplCalcFloatSize( this, nFloatLinesHeight );
    2087             : 
    2088           0 :     if( aCurrentSize == aSize1 )
    2089           0 :         return aSize1;
    2090             : 
    2091             :     // try to preserve current width
    2092             : 
    2093           0 :     long nLineHeight = ( mnWinHeight > mnMaxItemHeight ) ? mnWinHeight : mnMaxItemHeight;
    2094           0 :     int nBorderX = 2*TB_BORDER_OFFSET1 + mnLeftBorder + mnRightBorder;
    2095           0 :     int nBorderY = 2*TB_BORDER_OFFSET2 + mnTopBorder + mnBottomBorder;
    2096           0 :     Size aSz( aCurrentSize );
    2097             :     long maxX;
    2098           0 :     sal_uInt16 nLines = ImplCalcBreaks( aSz.Width()-nBorderX, &maxX, mbHorz );
    2099             : 
    2100           0 :     sal_uInt16 manyLines = 1000;
    2101           0 :     Size aMinimalFloatSize = ImplCalcFloatSize( this, manyLines );
    2102             : 
    2103           0 :     aSz.Height() = nBorderY + nLineHeight * nLines;
    2104             :     // line space when more than one line
    2105           0 :     if ( mnWinStyle & WB_LINESPACING )
    2106           0 :         aSz.Height() += (nLines-1)*TB_LINESPACING;
    2107             : 
    2108           0 :     aSz.Width() = nBorderX + maxX;
    2109             : 
    2110             :     // avoid clipping of any items
    2111           0 :     if( aSz.Width() < aMinimalFloatSize.Width() )
    2112           0 :         aSize2 = ImplCalcFloatSize( this, nLines );
    2113             :     else
    2114           0 :         aSize2 = aSz;
    2115             : 
    2116           0 :     if( aCurrentSize == aSize2 )
    2117           0 :         return aSize2;
    2118             : 
    2119             :     // set the size with the smallest delta as the current size
    2120           0 :     long dx1 = std::abs( mnDX - aSize1.Width() );
    2121           0 :     long dy1 = std::abs( mnDY - aSize1.Height() );
    2122             : 
    2123           0 :     long dx2 = std::abs( mnDX - aSize2.Width() );
    2124           0 :     long dy2 = std::abs( mnDY - aSize2.Height() );
    2125             : 
    2126           0 :     if( dx1*dy1 < dx2*dy2 )
    2127           0 :         aCurrentSize = aSize1;
    2128             :     else
    2129           0 :         aCurrentSize = aSize2;
    2130             : 
    2131           0 :     return aCurrentSize;
    2132             : }
    2133             : 
    2134             : namespace
    2135             : {
    2136        4443 : static void lcl_hideDoubleSeparators( std::vector< ImplToolItem >& rItems )
    2137             : {
    2138        4443 :     bool bLastSep( true );
    2139        4443 :     std::vector< ImplToolItem >::iterator it;
    2140       82961 :     for ( it = rItems.begin(); it != rItems.end(); ++it )
    2141             :     {
    2142       78518 :         if ( it->meType == TOOLBOXITEM_SEPARATOR )
    2143             :         {
    2144       17190 :             it->mbVisible = false;
    2145       17190 :             if ( !bLastSep )
    2146             :             {
    2147             :                 // check if any visible items have to appear behind it
    2148       15837 :                 std::vector< ImplToolItem >::iterator temp_it;
    2149       23718 :                 for ( temp_it = it+1; temp_it != rItems.end(); ++temp_it )
    2150             :                 {
    2151       44655 :                     if ( ((temp_it->meType == TOOLBOXITEM_BUTTON) &&
    2152       21714 :                           temp_it->mbVisible) )
    2153             :                     {
    2154       15060 :                         it->mbVisible = true;
    2155       15060 :                         break;
    2156             :                     }
    2157             :                 }
    2158             :             }
    2159       17190 :             bLastSep = true;
    2160             :         }
    2161       61328 :         else if ( it->mbVisible )
    2162       44204 :             bLastSep = false;
    2163             :     }
    2164        4443 : }
    2165             : }
    2166             : 
    2167       24282 : void ToolBox::ImplFormat( bool bResize )
    2168             : {
    2169             :     // Has to re-formatted
    2170       24282 :     if ( !mbFormat )
    2171       40452 :         return;
    2172             : 
    2173        8112 :     mpData->ImplClearLayoutData();
    2174             : 
    2175             :     // recalulate positions and sizes
    2176        8112 :     Rectangle       aEmptyRect;
    2177             :     long            nLineSize;
    2178             :     long            nLeft;
    2179             :     long            nTop;
    2180             :     long            nMax;   // width of layoutarea in pixels
    2181             :     sal_uInt16          nFormatLine;
    2182             :     bool            bMustFullPaint;
    2183             : 
    2184        8112 :     std::vector< ImplToolItem >::iterator   it;
    2185             : 
    2186        8112 :     ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
    2187        8112 :     bool bIsInPopupMode = ImplIsInPopupMode();
    2188             : 
    2189        8112 :     maFloatSizes.clear();
    2190             : 
    2191             :     // compute border sizes
    2192        8112 :     ImplCalcBorder( meAlign, mnLeftBorder, mnTopBorder, mnRightBorder, mnBottomBorder, this );
    2193             : 
    2194             :     // update drag area (where the 'grip' will be placed)
    2195        8112 :     Rectangle aOldDragRect;
    2196        8112 :     if( pWrapper )
    2197        4795 :         aOldDragRect = pWrapper->GetDragArea();
    2198        8112 :     ImplUpdateDragArea( this );
    2199             : 
    2200        8112 :     if ( ImplCalcItem() )
    2201        2626 :         bMustFullPaint = true;
    2202             :     else
    2203        5486 :         bMustFullPaint = false;
    2204             : 
    2205             :     // calculate new size during interactive resize or
    2206             :     // set computed size when formatting only
    2207        8112 :     if ( ImplIsFloatingMode() )
    2208             :     {
    2209           0 :         if ( bResize )
    2210           0 :             mnFloatLines = ImplCalcLines( this, mnDY );
    2211             :         else
    2212           0 :             SetOutputSizePixel( ImplGetOptimalFloatingSize() );
    2213             :     }
    2214             : 
    2215             :     // Horizontal
    2216        8112 :     if ( mbHorz )
    2217             :     {
    2218             :         long nBottom;
    2219             :         // nLineSize: height of a single line, will fit highest item
    2220        8112 :         nLineSize = mnMaxItemHeight;
    2221             : 
    2222        8112 :         if ( mnWinHeight > mnMaxItemHeight )
    2223          64 :             nLineSize = mnWinHeight;
    2224             : 
    2225        8112 :         if ( mbScroll )
    2226             :         {
    2227        5519 :             nMax        = mnDX;
    2228        5519 :             mnVisLines  = ImplCalcLines( this, mnDY );
    2229             :         }
    2230             :         else
    2231             :         {
    2232             :             // layout over all lines
    2233        2593 :             mnVisLines  = mnLines;
    2234        2593 :             nMax        = TB_MAXNOSCROLL;
    2235             :         }
    2236             : 
    2237             :         // add in all border offsets
    2238        8112 :         if ( mnWinStyle & WB_BORDER )
    2239             :         {
    2240        5519 :             nLeft       = TB_BORDER_OFFSET1 + mnLeftBorder;
    2241        5519 :             nTop        = TB_BORDER_OFFSET2 + mnTopBorder;
    2242        5519 :             nBottom     = TB_BORDER_OFFSET1 + mnBottomBorder;
    2243        5519 :             nMax       -= nLeft + TB_BORDER_OFFSET1 + mnRightBorder;
    2244             :         }
    2245             :         else
    2246             :         {
    2247        2593 :             nLeft       = 0;
    2248        2593 :             nTop        = 0;
    2249        2593 :             nBottom     = 0;
    2250             :         }
    2251             : 
    2252             :         // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
    2253             :         // we have to center all items in the window height
    2254        8112 :         if( IsMenuEnabled() && !ImplIsFloatingMode() )
    2255             :         {
    2256        5519 :             long  nWinHeight = mnDY - nTop - nBottom;
    2257        5519 :             if( nWinHeight > nLineSize )
    2258           0 :                 nLineSize = nWinHeight;
    2259             :         }
    2260             :     }
    2261             :     else
    2262             :     {
    2263             :         long nRight;
    2264           0 :         nLineSize = mnMaxItemWidth;
    2265             : 
    2266           0 :         if ( mbScroll )
    2267             :         {
    2268           0 :             mnVisLines  = ImplCalcLines( this, mnDX );
    2269           0 :             nMax        = mnDY;
    2270             :         }
    2271             :         else
    2272             :         {
    2273           0 :             mnVisLines  = mnLines;
    2274           0 :             nMax        = TB_MAXNOSCROLL;
    2275             :         }
    2276             : 
    2277           0 :         if ( mnWinStyle & WB_BORDER )
    2278             :         {
    2279           0 :             nTop        = TB_BORDER_OFFSET1 + mnTopBorder;
    2280           0 :             nLeft       = TB_BORDER_OFFSET2 + mnLeftBorder;
    2281           0 :             nRight      = TB_BORDER_OFFSET2 + mnRightBorder;
    2282           0 :             nMax       -= nTop + TB_BORDER_OFFSET1 + mnBottomBorder;
    2283             :         }
    2284             :         else
    2285             :         {
    2286           0 :             nLeft       = 0;
    2287           0 :             nTop        = 0;
    2288           0 :             nRight      = 0;
    2289             :         }
    2290             : 
    2291             :         // adjust linesize if docked in single-line mode (i.e. when using a clipped item menu)
    2292             :         // we have to center all items in the window height
    2293           0 :         if( !ImplIsFloatingMode() && IsMenuEnabled() )
    2294             :         {
    2295           0 :             long  nWinWidth = mnDX - nLeft - nRight;
    2296           0 :             if( nWinWidth > nLineSize )
    2297           0 :                 nLineSize = nWinWidth;
    2298             :         }
    2299             :     }
    2300             : 
    2301             :     // no calculation if the window has no size (nMax=0)
    2302             :     // non scrolling toolboxes must be computed though
    2303        8112 :     if ( (nMax <= 0) && mbScroll )
    2304             :     {
    2305        3658 :         mnVisLines   = 1;
    2306        3658 :         mnCurLine    = 1;
    2307        3658 :         mnCurLines   = 1;
    2308             : 
    2309        3658 :         it = mpData->m_aItems.begin();
    2310       39664 :         while ( it != mpData->m_aItems.end() )
    2311             :         {
    2312       32348 :             it->maRect = aEmptyRect;
    2313       32348 :             ++it;
    2314             :         }
    2315             : 
    2316        3658 :         maLowerRect = aEmptyRect;
    2317        3658 :         maUpperRect = aEmptyRect;
    2318             :     }
    2319             :     else
    2320             :     {
    2321             :         // init start values
    2322        4454 :         long nX = nLeft;    // top-left offset
    2323        4454 :         long nY = nTop;
    2324        4454 :         nFormatLine = 1;
    2325             : 
    2326             :         // save old scroll rectangles and reset them
    2327        4454 :         Rectangle aOldLowerRect = maLowerRect;
    2328        4454 :         Rectangle aOldUpperRect = maUpperRect;
    2329        4454 :         Rectangle aOldMenubuttonRect = mpData->maMenubuttonItem.maRect;
    2330        4454 :         maUpperRect = aEmptyRect;
    2331        4454 :         maLowerRect = aEmptyRect;
    2332        4454 :         mpData->maMenubuttonItem.maRect = aEmptyRect;
    2333             : 
    2334             :         // do we have any toolbox items at all ?
    2335        4454 :         if ( !mpData->m_aItems.empty() || IsMenuEnabled() )
    2336             :         {
    2337        4443 :             lcl_hideDoubleSeparators( mpData->m_aItems );
    2338             : 
    2339             :             // compute line breaks and visible lines give the current window width (nMax)
    2340             :             // the break indicators will be stored within each item (it->mbBreak)
    2341        4443 :             mnCurLines = ImplCalcBreaks( nMax, NULL, mbHorz );
    2342             : 
    2343             :             // check for scrollbar buttons or dropdown menu
    2344             :             // (if a menu is enabled, this will be used to store clipped
    2345             :             //  items and no scroll buttons will appear)
    2346        8717 :             if ( (!ImplIsFloatingMode() && (mnCurLines > mnVisLines) && mbScroll ) ||
    2347        4274 :                 IsMenuEnabled() )
    2348             :             {
    2349             :                 // compute linebreaks again, incorporating scrollbar buttons
    2350        1861 :                 if( !IsMenuEnabled() )
    2351             :                 {
    2352           0 :                     nMax -= TB_SPIN_SIZE+TB_SPIN_OFFSET;
    2353           0 :                     mnCurLines = ImplCalcBreaks( nMax, NULL, mbHorz );
    2354             :                 }
    2355             : 
    2356             :                 // compute scroll rectangles or menu button
    2357        1861 :                 if ( mbHorz )
    2358             :                 {
    2359        1861 :                     if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
    2360             :                     {
    2361        1861 :                         if( !ImplIsFloatingMode() )
    2362             :                         {
    2363        1861 :                             mpData->maMenubuttonItem.maRect.Right() = mnDX - 2;
    2364        1861 :                             mpData->maMenubuttonItem.maRect.Top() = nTop;
    2365        1861 :                             mpData->maMenubuttonItem.maRect.Bottom() = mnDY-mnBottomBorder-TB_BORDER_OFFSET2-1;
    2366             :                         }
    2367             :                         else
    2368             :                         {
    2369           0 :                             mpData->maMenubuttonItem.maRect.Right() = mnDX - mnRightBorder-TB_BORDER_OFFSET1-1;
    2370           0 :                             mpData->maMenubuttonItem.maRect.Top() = nTop;
    2371           0 :                             mpData->maMenubuttonItem.maRect.Bottom() = mnDY-mnBottomBorder-TB_BORDER_OFFSET2-1;
    2372             :                         }
    2373        1861 :                         mpData->maMenubuttonItem.maRect.Left() = mpData->maMenubuttonItem.maRect.Right() - mpData->mnMenuButtonWidth;
    2374             :                     }
    2375             :                     else
    2376             :                     {
    2377           0 :                         maUpperRect.Left()   = nLeft+nMax+TB_SPIN_OFFSET;
    2378           0 :                         maUpperRect.Right()  = maUpperRect.Left()+TB_SPIN_SIZE-1;
    2379           0 :                         maUpperRect.Top()    = nTop;
    2380           0 :                         maLowerRect.Bottom() = mnDY-mnBottomBorder-TB_BORDER_OFFSET2-1;
    2381           0 :                         maLowerRect.Left()   = maUpperRect.Left();
    2382           0 :                         maLowerRect.Right()  = maUpperRect.Right();
    2383           0 :                         maUpperRect.Bottom() = maUpperRect.Top() +
    2384           0 :                                             (maLowerRect.Bottom()-maUpperRect.Top())/2;
    2385           0 :                         maLowerRect.Top()    = maUpperRect.Bottom();
    2386             :                     }
    2387             :                 }
    2388             :                 else
    2389             :                 {
    2390           0 :                     if( IsMenuEnabled() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
    2391             :                     {
    2392           0 :                         if( !ImplIsFloatingMode() )
    2393             :                         {
    2394           0 :                             mpData->maMenubuttonItem.maRect.Bottom() = mnDY - 2;
    2395           0 :                             mpData->maMenubuttonItem.maRect.Left() = nLeft;
    2396           0 :                             mpData->maMenubuttonItem.maRect.Right() = mnDX-mnRightBorder-TB_BORDER_OFFSET2-1;
    2397             :                         }
    2398             :                         else
    2399             :                         {
    2400           0 :                             mpData->maMenubuttonItem.maRect.Bottom() = mnDY - mnBottomBorder-TB_BORDER_OFFSET1-1;
    2401           0 :                             mpData->maMenubuttonItem.maRect.Left() = nLeft;
    2402           0 :                             mpData->maMenubuttonItem.maRect.Right() = mnDX-mnRightBorder-TB_BORDER_OFFSET2-1;
    2403             :                         }
    2404           0 :                         mpData->maMenubuttonItem.maRect.Top() = mpData->maMenubuttonItem.maRect.Bottom() - mpData->mnMenuButtonWidth;
    2405             :                     }
    2406             :                     else
    2407             :                     {
    2408           0 :                         maUpperRect.Top()    = nTop+nMax+TB_SPIN_OFFSET;
    2409           0 :                         maUpperRect.Bottom() = maUpperRect.Top()+TB_SPIN_SIZE-1;
    2410           0 :                         maUpperRect.Left()   = nLeft;
    2411           0 :                         maLowerRect.Right()  = mnDX-mnRightBorder-TB_BORDER_OFFSET2-1;
    2412           0 :                         maLowerRect.Top()    = maUpperRect.Top();
    2413           0 :                         maLowerRect.Bottom() = maUpperRect.Bottom();
    2414           0 :                         maUpperRect.Right()  = maUpperRect.Left() +
    2415           0 :                                             (maLowerRect.Right()-maUpperRect.Left())/2;
    2416           0 :                         maLowerRect.Left()   = maUpperRect.Right();
    2417             :                     }
    2418             :                 }
    2419             :             }
    2420             : 
    2421             :             // no scrolling when there is a "more"-menu
    2422             :             // anything will "fit" in a single line then
    2423        4443 :             if( IsMenuEnabled() )
    2424        1861 :                 mnCurLines = 1;
    2425             : 
    2426             :             // determine the currently visible line
    2427        4443 :             if ( mnVisLines >= mnCurLines )
    2428        4443 :                 mnCurLine = 1;
    2429           0 :             else if ( mnCurLine+mnVisLines-1 > mnCurLines )
    2430           0 :                 mnCurLine = mnCurLines - (mnVisLines-1);
    2431             : 
    2432        4443 :             it = mpData->m_aItems.begin();
    2433       87404 :             while ( it != mpData->m_aItems.end() )
    2434             :             {
    2435       78518 :                 it->mbShowWindow = false;
    2436             : 
    2437             :                 // check for line break and advance nX/nY accordingly
    2438       78518 :                 if ( it->mbBreak )
    2439             :                 {
    2440         238 :                     nFormatLine++;
    2441             : 
    2442             :                     // increment starting with the second line
    2443         238 :                     if ( nFormatLine > mnCurLine )
    2444             :                     {
    2445         238 :                         if ( mbHorz )
    2446             :                         {
    2447         238 :                             nX = nLeft;
    2448         238 :                             if ( mnWinStyle & WB_LINESPACING )
    2449         170 :                                 nY += nLineSize+TB_LINESPACING;
    2450             :                             else
    2451          68 :                                 nY += nLineSize;
    2452             :                         }
    2453             :                         else
    2454             :                         {
    2455           0 :                             nY = nTop;
    2456           0 :                             if ( mnWinStyle & WB_LINESPACING )
    2457           0 :                                 nX += nLineSize+TB_LINESPACING;
    2458             :                             else
    2459           0 :                                 nX += nLineSize;
    2460             :                         }
    2461             :                     }
    2462             :                 }
    2463             : 
    2464      137782 :                 if ( !it->mbVisible || (nFormatLine < mnCurLine) ||
    2465       59264 :                      (nFormatLine > mnCurLine+mnVisLines-1) )
    2466             :                      // item is not visible
    2467       19735 :                     it->maCalcRect = aEmptyRect;
    2468             :                 else
    2469             :                 {
    2470             :                     // 1. determine current item width/height
    2471             :                     // take window size and orientation into account, because this affects the size of item windows
    2472             : 
    2473       58783 :                     Size aCurrentItemSize( it->GetSize( mbHorz, mbScroll, nMax, Size(mnMaxItemWidth, mnMaxItemHeight) ) );
    2474             : 
    2475             :                     // 2. position item rect and use size from step 1
    2476             :                     //  items will be centered horizontally (if mbHorz) or vertically
    2477             :                     //  advance nX and nY accordingly
    2478       58783 :                     if ( mbHorz )
    2479             :                     {
    2480       58783 :                         it->maCalcRect.Left()     = nX;
    2481             :                         // if special TBX_LAYOUT_LOCKVERT lock vertical position
    2482             :                         // don't recalulate the vertical position of the item
    2483       58783 :                         if ( meLayoutMode == TBX_LAYOUT_LOCKVERT && mnLines == 1 )
    2484             :                         {
    2485             :                             // Somewhat of a hack here, calc deletes and re-adds
    2486             :                             // the sum/assign & ok/cancel items dynamically.
    2487             :                             // Because TBX_LAYOUT_LOCKVERT effectively prevents
    2488             :                             // recalculation of the vertical pos of an item the
    2489             :                             // it->maRect.Top() for those newly added items is
    2490             :                             // 0. The hack here is that we want to effectively
    2491             :                             // recalculate the vertical pos for those added
    2492             :                             // items here. ( Note: assume mnMaxItemHeight is
    2493             :                             // equal to the LineSize when multibar has a single
    2494             :                             // line size )
    2495           0 :                             it->maCalcRect.Top()      =  it->maRect.Top() ? it->maRect.Top() : ( nY + ( mnMaxItemHeight-aCurrentItemSize.Height())/2 );
    2496             :                         }
    2497             :                         else
    2498       58783 :                             it->maCalcRect.Top()      = nY+(nLineSize-aCurrentItemSize.Height())/2;
    2499       58783 :                         it->maCalcRect.Right()    = nX+aCurrentItemSize.Width()-1;
    2500       58783 :                         it->maCalcRect.Bottom()   = it->maCalcRect.Top()+aCurrentItemSize.Height()-1;
    2501       58783 :                         nX += aCurrentItemSize.Width();
    2502             :                     }
    2503             :                     else
    2504             :                     {
    2505           0 :                         it->maCalcRect.Left()     = nX+(nLineSize-aCurrentItemSize.Width())/2;
    2506           0 :                         it->maCalcRect.Top()      = nY;
    2507           0 :                         it->maCalcRect.Right()    = it->maCalcRect.Left()+aCurrentItemSize.Width()-1;
    2508           0 :                         it->maCalcRect.Bottom()   = nY+aCurrentItemSize.Height()-1;
    2509           0 :                         nY += aCurrentItemSize.Height();
    2510             :                     }
    2511             :                 }
    2512             : 
    2513             :                 // position window items into calculated item rect
    2514       78518 :                 if ( it->mpWindow )
    2515             :                 {
    2516        3937 :                     if ( it->mbShowWindow )
    2517             :                     {
    2518        3514 :                         Point aPos( it->maCalcRect.Left(), it->maCalcRect.Top() );
    2519        3514 :                         it->mpWindow->SetPosPixel( aPos );
    2520        3514 :                         if ( !mbCustomizeMode )
    2521        3514 :                             it->mpWindow->Show();
    2522             :                     }
    2523             :                     else
    2524         423 :                         it->mpWindow->Hide();
    2525             :                 }
    2526             : 
    2527       78518 :                 ++it;
    2528             :             } // end of loop over all items
    2529             :         }
    2530             :         else
    2531             :             // we have no toolbox items
    2532          11 :             mnCurLines = 1;
    2533             : 
    2534        4454 :         if( IsMenuEnabled() && ImplIsFloatingMode() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
    2535             :         {
    2536             :             // custom menu will be the last button in floating mode
    2537           0 :             ImplToolItem &rIt = mpData->maMenubuttonItem;
    2538             : 
    2539           0 :             if ( mbHorz )
    2540             :             {
    2541           0 :                 rIt.maRect.Left()     = nX+TB_MENUBUTTON_OFFSET;
    2542           0 :                 rIt.maRect.Top()      = nY;
    2543           0 :                 rIt.maRect.Right()    = rIt.maRect.Left() + mpData->mnMenuButtonWidth;
    2544           0 :                 rIt.maRect.Bottom()   = nY+nLineSize-1;
    2545           0 :                 nX += rIt.maItemSize.Width();
    2546             :             }
    2547             :             else
    2548             :             {
    2549           0 :                 rIt.maRect.Left()     = nX;
    2550           0 :                 rIt.maRect.Top()      = nY+TB_MENUBUTTON_OFFSET;
    2551           0 :                 rIt.maRect.Right()    = nX+nLineSize-1;
    2552           0 :                 rIt.maRect.Bottom()   = rIt.maRect.Top() + mpData->mnMenuButtonWidth;
    2553           0 :                 nY += rIt.maItemSize.Height();
    2554             :             }
    2555             :         }
    2556             : 
    2557             :         // if toolbox visible trigger paint for changed regions
    2558        4454 :         if ( IsVisible() && !mbFullPaint )
    2559             :         {
    2560        4275 :             if ( bMustFullPaint )
    2561             :             {
    2562             :                 maPaintRect = Rectangle( mnLeftBorder, mnTopBorder,
    2563        2040 :                                          mnDX-mnRightBorder, mnDY-mnBottomBorder );
    2564             :             }
    2565             :             else
    2566             :             {
    2567        2235 :                 if ( aOldLowerRect != maLowerRect )
    2568             :                 {
    2569           0 :                     maPaintRect.Union( maLowerRect );
    2570           0 :                     maPaintRect.Union( aOldLowerRect );
    2571             :                 }
    2572        2235 :                 if ( aOldUpperRect != maUpperRect )
    2573             :                 {
    2574           0 :                     maPaintRect.Union( maUpperRect );
    2575           0 :                     maPaintRect.Union( aOldUpperRect );
    2576             :                 }
    2577        2235 :                 if ( aOldMenubuttonRect != mpData->maMenubuttonItem.maRect )
    2578             :                 {
    2579        1842 :                     maPaintRect.Union( mpData->maMenubuttonItem.maRect );
    2580        1842 :                     maPaintRect.Union( aOldMenubuttonRect );
    2581             :                 }
    2582        2235 :                 if ( pWrapper && aOldDragRect != pWrapper->GetDragArea() )
    2583             :                 {
    2584        1436 :                     maPaintRect.Union( pWrapper->GetDragArea() );
    2585        1436 :                     maPaintRect.Union( aOldDragRect );
    2586             :                 }
    2587             : 
    2588        2235 :                 it = mpData->m_aItems.begin();
    2589       77585 :                 while ( it != mpData->m_aItems.end() )
    2590             :                 {
    2591       73115 :                     if ( it->maRect != it->maCalcRect )
    2592             :                     {
    2593       43801 :                         maPaintRect.Union( it->maRect );
    2594       43801 :                         maPaintRect.Union( it->maCalcRect );
    2595             :                     }
    2596       73115 :                     ++it;
    2597             :                 }
    2598             :             }
    2599             : 
    2600        4275 :             Invalidate( maPaintRect );
    2601             :         }
    2602             : 
    2603             :         // store the new calculated item rects
    2604        4454 :         maPaintRect = aEmptyRect;
    2605        4454 :         it = mpData->m_aItems.begin();
    2606       87426 :         while ( it != mpData->m_aItems.end() )
    2607             :         {
    2608       78518 :             it->maRect = it->maCalcRect;
    2609       78518 :             ++it;
    2610             :         }
    2611             :     }
    2612             : 
    2613             :     // indicate formatting is done
    2614        8112 :     mbFormat = false;
    2615             : }
    2616             : 
    2617           0 : IMPL_LINK_NOARG(ToolBox, ImplDropdownLongClickHdl)
    2618             : {
    2619           0 :     if( mnCurPos != TOOLBOX_ITEM_NOTFOUND &&
    2620           0 :         (mpData->m_aItems[ mnCurPos ].mnBits & TIB_DROPDOWN)
    2621             :         )
    2622             :     {
    2623           0 :         mpData->mbDropDownByKeyboard = false;
    2624           0 :         GetDropdownClickHdl().Call( this );
    2625             : 
    2626             :         // do not reset data if the dropdown handler opened a floating window
    2627             :         // see ImplFloatControl()
    2628           0 :         if( mpFloatWin == NULL )
    2629             :         {
    2630             :             // no floater was opened
    2631           0 :             Deactivate();
    2632           0 :             ImplDrawItem( mnCurPos, 0 );
    2633             : 
    2634           0 :             mnCurPos         = TOOLBOX_ITEM_NOTFOUND;
    2635           0 :             mnCurItemId      = 0;
    2636           0 :             mnDownItemId     = 0;
    2637           0 :             mnMouseClicks    = 0;
    2638           0 :             mnMouseModifier  = 0;
    2639           0 :             mnHighItemId     = 0;
    2640             :         }
    2641             :     }
    2642             : 
    2643           0 :     return 0;
    2644             : }
    2645             : 
    2646          98 : IMPL_LINK_NOARG(ToolBox, ImplUpdateHdl)
    2647             : {
    2648             : 
    2649          49 :     if( mbFormat )
    2650          48 :         ImplFormat();
    2651             : 
    2652          49 :     return 0;
    2653             : }
    2654             : 
    2655         343 : static void ImplDrawMoreIndicator( ToolBox *pBox, const Rectangle& rRect, bool bSetColor, bool bRotate )
    2656             : {
    2657         343 :     Color aOldFillColor = pBox->GetFillColor();
    2658         343 :     Color aOldLineColor = pBox->GetLineColor();
    2659         343 :     pBox->SetLineColor();
    2660             : 
    2661         343 :     if ( bSetColor )
    2662             :     {
    2663         343 :         if ( pBox->GetSettings().GetStyleSettings().GetFaceColor().IsDark() )
    2664           0 :             pBox->SetFillColor( Color( COL_WHITE ) );
    2665             :         else
    2666         343 :             pBox->SetFillColor( Color( COL_BLACK ) );
    2667             :     }
    2668             : 
    2669         343 :     int linewidth = 1 * pBox->GetDPIScaleFactor();
    2670         343 :     int space = 4 * pBox->GetDPIScaleFactor();
    2671             : 
    2672         343 :     if( !bRotate )
    2673             :     {
    2674         343 :         long width = 8 * pBox->GetDPIScaleFactor();
    2675         343 :         long height = 5 * pBox->GetDPIScaleFactor();
    2676             : 
    2677             :         //Keep odd b/c drawing code works better
    2678         343 :         if ( height % 2 == 0 )
    2679           0 :             height--;
    2680             : 
    2681         343 :         long heightOrig = height;
    2682             : 
    2683         343 :         long x = rRect.Left() + (rRect.getWidth() - width)/2 + 1;
    2684         343 :         long y = rRect.Top() + (rRect.getHeight() - height)/2 + 1;
    2685        2401 :         while( height >= 1)
    2686             :         {
    2687        1715 :             pBox->DrawRect( Rectangle( x, y, x + linewidth, y ) );
    2688        1715 :             x += space;
    2689        1715 :             pBox->DrawRect( Rectangle( x, y, x + linewidth, y ) );
    2690        1715 :             x -= space;
    2691        1715 :             y++;
    2692        1715 :             if( height <= heightOrig / 2 + 1) x--;
    2693         686 :             else            x++;
    2694        1715 :             height--;
    2695             :         }
    2696             :     }
    2697             :     else
    2698             :     {
    2699           0 :         long width = 5 * pBox->GetDPIScaleFactor();
    2700           0 :         long height = 8 * pBox->GetDPIScaleFactor();
    2701             : 
    2702             :         //Keep odd b/c drawing code works better
    2703           0 :         if (width % 2 == 0)
    2704           0 :             width--;
    2705             : 
    2706           0 :         long widthOrig = width;
    2707             : 
    2708           0 :         long x = rRect.Left() + (rRect.getWidth() - width)/2 + 1;
    2709           0 :         long y = rRect.Top() + (rRect.getHeight() - height)/2 + 1;
    2710           0 :         while( width >= 1)
    2711             :         {
    2712           0 :             pBox->DrawRect( Rectangle( x, y, x, y + linewidth ) );
    2713           0 :             y += space;
    2714           0 :             pBox->DrawRect( Rectangle( x, y, x, y + linewidth ) );
    2715           0 :             y -= space;
    2716           0 :             x++;
    2717           0 :             if( width <= widthOrig / 2 + 1) y--;
    2718           0 :             else           y++;
    2719           0 :             width--;
    2720             :         }
    2721             :     }
    2722             : 
    2723         343 :     pBox->SetFillColor( aOldFillColor );
    2724         343 :     pBox->SetLineColor( aOldLineColor );
    2725         343 : }
    2726             : 
    2727       13498 : static void ImplDrawDropdownArrow( ToolBox *pBox, const Rectangle& rDropDownRect, bool bSetColor, bool bRotate )
    2728             : {
    2729       13498 :     bool bLineColor = pBox->IsLineColor();
    2730       13498 :     bool bFillColor = pBox->IsFillColor();
    2731       13498 :     Color aOldFillColor = pBox->GetFillColor();
    2732       13498 :     Color aOldLineColor = pBox->GetLineColor();
    2733       13498 :     pBox->SetLineColor();
    2734             : 
    2735       13498 :     if ( bSetColor )
    2736             :     {
    2737       10723 :         if ( pBox->GetSettings().GetStyleSettings().GetFaceColor().IsDark() )
    2738           0 :             pBox->SetFillColor( Color( COL_WHITE ) );
    2739             :         else
    2740       10723 :             pBox->SetFillColor( Color( COL_BLACK ) );
    2741             :     }
    2742             : 
    2743       13498 :     if( !bRotate )
    2744             :     {
    2745       13498 :         long width = 5 * pBox->GetDPIScaleFactor();
    2746       13498 :         long height = 3 * pBox->GetDPIScaleFactor();
    2747             : 
    2748       13498 :         long x = rDropDownRect.Left() + (rDropDownRect.getWidth() - width)/2;
    2749       13498 :         long y = rDropDownRect.Top() + (rDropDownRect.getHeight() - height)/2;
    2750       67490 :         while( width >= 1)
    2751             :         {
    2752       40494 :             pBox->DrawRect( Rectangle( x, y, x+width-1, y ) );
    2753       40494 :             y++; x++;
    2754       40494 :             width -= 2;
    2755             :         }
    2756             :     }
    2757             :     else
    2758             :     {
    2759           0 :         long width = 3 * pBox->GetDPIScaleFactor();
    2760           0 :         long height = 5 * pBox->GetDPIScaleFactor();
    2761             : 
    2762           0 :         long x = rDropDownRect.Left() + (rDropDownRect.getWidth() - width)/2;
    2763           0 :         long y = rDropDownRect.Top() + (rDropDownRect.getHeight() - height)/2;
    2764           0 :         while( height >= 1)
    2765             :         {
    2766           0 :             pBox->DrawRect( Rectangle( x, y, x, y+height-1 ) );
    2767           0 :             y++; x++;
    2768           0 :             height -= 2;
    2769             :         }
    2770             :     }
    2771             : 
    2772       13498 :     if( bFillColor )
    2773        2775 :         pBox->SetFillColor( aOldFillColor );
    2774             :     else
    2775       10723 :         pBox->SetFillColor();
    2776       13498 :     if( bLineColor )
    2777       13498 :         pBox->SetLineColor( aOldLineColor );
    2778             :     else
    2779           0 :         pBox->SetLineColor( );
    2780       13498 : }
    2781             : 
    2782       10054 : void ToolBox::ImplDrawMenubutton( ToolBox *pThis, bool bHighlight )
    2783             : {
    2784       10054 :     if( !pThis->mpData->maMenubuttonItem.maRect.IsEmpty() )
    2785             :     {
    2786             :         // #i53937# paint menu button only if necessary
    2787        3819 :         if( !pThis->ImplHasClippedItems() )
    2788       13530 :             return;
    2789             : 
    2790             :         // execute pending paint requests
    2791         343 :         ImplCheckUpdate( pThis );
    2792             : 
    2793         343 :         bool bFillColor = pThis->IsFillColor();
    2794         343 :         bool bLineColor = pThis->IsLineColor();
    2795         343 :         Color aOldFillCol = pThis->GetFillColor();
    2796         343 :         Color aOldLineCol = pThis->GetLineColor();
    2797             : 
    2798             :         // draw the 'more' indicator / button (>>)
    2799         343 :         ImplErase( pThis, pThis->mpData->maMenubuttonItem.maRect, bHighlight );
    2800             : 
    2801         343 :         if( bHighlight )
    2802           0 :             ImplDrawButton( pThis, pThis->mpData->maMenubuttonItem.maRect, 2, false, true, false );
    2803             : 
    2804         343 :         if( pThis->ImplHasClippedItems() )
    2805         343 :             ImplDrawMoreIndicator( pThis, pThis->mpData->maMenubuttonItem.maRect, true, !pThis->mbHorz );
    2806             : 
    2807             :         // store highlight state
    2808         343 :         pThis->mpData->mbMenubuttonSelected = bHighlight;
    2809             : 
    2810             :         // restore colors
    2811         343 :         if( bFillColor )
    2812         165 :             pThis->SetFillColor( aOldFillCol );
    2813             :         else
    2814         178 :             pThis->SetFillColor();
    2815         343 :         if( bLineColor )
    2816         343 :             pThis->SetLineColor( aOldLineCol );
    2817             :         else
    2818           0 :             pThis->SetLineColor();
    2819             :     }
    2820             : }
    2821             : 
    2822           0 : void ToolBox::ImplDrawSpin( bool bUpperIn, bool bLowerIn )
    2823             : {
    2824             : 
    2825             :     bool    bTmpUpper;
    2826             :     bool    bTmpLower;
    2827             : 
    2828           0 :     if ( maUpperRect.IsEmpty() || maLowerRect.IsEmpty() )
    2829           0 :         return;
    2830             : 
    2831           0 :     if ( mnCurLine > 1 )
    2832           0 :         bTmpUpper = true;
    2833             :     else
    2834           0 :         bTmpUpper = false;
    2835             : 
    2836           0 :     if ( mnCurLine+mnVisLines-1 < mnCurLines )
    2837           0 :         bTmpLower = true;
    2838             :     else
    2839           0 :         bTmpLower = false;
    2840             : 
    2841           0 :     if ( !IsEnabled() )
    2842             :     {
    2843           0 :         bTmpUpper = false;
    2844           0 :         bTmpLower = false;
    2845             :     }
    2846             : 
    2847             :     ImplDrawSpinButton( this, maUpperRect, maLowerRect,
    2848           0 :                         bUpperIn, bLowerIn, bTmpUpper, bTmpLower, !mbHorz );
    2849             : }
    2850             : 
    2851       22187 : void ToolBox::ImplDrawSeparator( sal_uInt16 nPos, Rectangle rRect )
    2852             : {
    2853       22187 :     bool bNativeOk = false;
    2854       22187 :     ImplToolItem* pItem = &mpData->m_aItems[nPos];
    2855             : 
    2856       22187 :     ControlPart nPart = IsHorizontal() ? PART_SEPARATOR_VERT : PART_SEPARATOR_HORZ;
    2857       22187 :     if( IsNativeControlSupported( CTRL_TOOLBAR, nPart ) )
    2858             :     {
    2859           0 :         ImplControlValue    aControlValue;
    2860           0 :         ControlState        nState = 0;
    2861             :         bNativeOk = DrawNativeControl( CTRL_TOOLBAR, nPart,
    2862           0 :                                        rRect, nState, aControlValue, OUString() );
    2863             :     }
    2864             : 
    2865             :     /* Draw the widget only if it can't be drawn natively. */
    2866       22187 :     if( !bNativeOk )
    2867             :     {
    2868       22187 :         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
    2869       22187 :         ImplToolItem* pTempItem = &mpData->m_aItems[nPos-1];
    2870             : 
    2871             :         // no separator before or after windows or at breaks
    2872       22187 :         if ( pTempItem && !pTempItem->mbShowWindow && nPos < mpData->m_aItems.size()-1 )
    2873             :         {
    2874       18958 :             pTempItem = &mpData->m_aItems[nPos+1];
    2875       18958 :             if ( !pTempItem->mbShowWindow && !pTempItem->mbBreak )
    2876             :             {
    2877             :                 long nCenterPos, nSlim;
    2878       17629 :                 SetLineColor( rStyleSettings.GetSeparatorColor() );
    2879       17629 :                 if ( IsHorizontal() )
    2880             :                 {
    2881       17629 :                     nSlim = (pItem->maRect.Bottom() - pItem->maRect.Top ()) / 4;
    2882       17629 :                     nCenterPos = pItem->maRect.Center().X();
    2883       17629 :                     DrawLine( Point( nCenterPos, pItem->maRect.Top() + nSlim ),
    2884       35258 :                               Point( nCenterPos, pItem->maRect.Bottom() - nSlim ) );
    2885             :                 }
    2886             :                 else
    2887             :                 {
    2888           0 :                     nSlim = (pItem->maRect.Right() - pItem->maRect.Left ()) / 4;
    2889           0 :                     nCenterPos = pItem->maRect.Center().Y();
    2890           0 :                     DrawLine( Point( pItem->maRect.Left() + nSlim, nCenterPos ),
    2891           0 :                               Point( pItem->maRect.Right() - nSlim, nCenterPos ) );
    2892             :                 }
    2893             :             }
    2894             :         }
    2895             :     }
    2896       22187 : }
    2897             : 
    2898        3723 : static void ImplDrawButton( ToolBox* pThis, const Rectangle &rRect, sal_uInt16 highlight, bool bChecked, bool bEnabled, bool bIsWindow )
    2899             : {
    2900             :     // draws toolbar button background either native or using a coloured selection
    2901             :     // if bIsWindow is true, the corresponding item is a control and only a selection border will be drawn
    2902             : 
    2903        3723 :     bool bNativeOk = false;
    2904        3723 :     if( !bIsWindow && pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_BUTTON ) )
    2905             :     {
    2906           0 :         ImplControlValue    aControlValue;
    2907           0 :         ControlState        nState = 0;
    2908             : 
    2909           0 :         if ( highlight == 1 )   nState |= CTRL_STATE_PRESSED;
    2910           0 :         if ( highlight == 2 )     nState |= CTRL_STATE_ROLLOVER;
    2911           0 :         if ( bEnabled )         nState |= CTRL_STATE_ENABLED;
    2912             : 
    2913           0 :         aControlValue.setTristateVal( bChecked ? BUTTONVALUE_ON : BUTTONVALUE_OFF );
    2914             : 
    2915             :         bNativeOk = pThis->DrawNativeControl( CTRL_TOOLBAR, PART_BUTTON,
    2916           0 :                                               rRect, nState, aControlValue, OUString() );
    2917             :     }
    2918             : 
    2919        3723 :     if( !bNativeOk )
    2920        3723 :         pThis->DrawSelectionBackground( rRect, bIsWindow ? 3 : highlight, bChecked, true, bIsWindow, 2, NULL, NULL );
    2921        3723 : }
    2922             : 
    2923       88523 : void ToolBox::ImplDrawItem( sal_uInt16 nPos, sal_uInt16 nHighlight, bool bPaint, bool bLayout )
    2924             : {
    2925             : 
    2926       88523 :     if( nPos >= mpData->m_aItems.size() )
    2927       26462 :         return;
    2928             : 
    2929             :     // execute pending paint requests
    2930       88523 :     ImplCheckUpdate( this );
    2931             : 
    2932       88523 :     ImplDisableFlatButtons();
    2933             : 
    2934       88523 :     SetFillColor();
    2935             : 
    2936       88523 :     ImplToolItem* pItem = &mpData->m_aItems[nPos];
    2937       88523 :     MetricVector* pVector = bLayout ? &mpData->m_pLayoutData->m_aUnicodeBoundRects : NULL;
    2938       88523 :     OUString* pDisplayText = bLayout ? &mpData->m_pLayoutData->m_aDisplayText : NULL;
    2939             : 
    2940       88523 :     if(!pItem->mbEnabled)
    2941       30443 :         nHighlight = 0;
    2942             : 
    2943             :     // if the rectangle is outside visible area
    2944       88523 :     if ( pItem->maRect.IsEmpty() )
    2945           0 :         return;
    2946             : 
    2947       88523 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
    2948             : 
    2949             :     // no gradient background for items that have a popup open
    2950       88523 :     bool bHasOpenPopup = (mpFloatWin != NULL) && (mnDownItemId==pItem->mnId);
    2951             : 
    2952       88523 :     bool bHighContrastWhite = false;
    2953             :     // check the face color as highcontrast indicator
    2954             :     // because the toolbox itself might have a gradient
    2955       88523 :     if( rStyleSettings.GetFaceColor() == Color( COL_WHITE ) )
    2956           0 :         bHighContrastWhite = true;
    2957             : 
    2958             :     // Compute buttons area.
    2959       88523 :     Size    aBtnSize    = pItem->maRect.GetSize();
    2960       88523 :     if( ImplGetSVData()->maNWFData.mbToolboxDropDownSeparate )
    2961             :     {
    2962             :         // separate button not for dropdown only where the whole button is painted
    2963           0 :         if ( pItem->mnBits & TIB_DROPDOWN &&
    2964           0 :             ((pItem->mnBits & TIB_DROPDOWNONLY) != TIB_DROPDOWNONLY) )
    2965             :         {
    2966           0 :             Rectangle aArrowRect = pItem->GetDropDownRect( mbHorz );
    2967           0 :             if( aArrowRect.Top() == pItem->maRect.Top() ) // dropdown arrow on right side
    2968           0 :                 aBtnSize.Width() -= aArrowRect.GetWidth();
    2969             :             else // dropdown arrow on bottom side
    2970           0 :                 aBtnSize.Height() -= aArrowRect.GetHeight();
    2971             :         }
    2972             :     }
    2973             : 
    2974             :     /* Compute the button/separator rectangle here, we'll need it for
    2975             :      * both the buttons and the separators. */
    2976       88523 :     Rectangle aButtonRect( pItem->maRect.TopLeft(), aBtnSize );
    2977       88523 :     long    nOffX       = SMALLBUTTON_OFF_NORMAL_X;
    2978       88523 :     long    nOffY       = SMALLBUTTON_OFF_NORMAL_Y;
    2979       88523 :     long    nImageOffX  = 0;
    2980       88523 :     long    nImageOffY  = 0;
    2981       88523 :     sal_uInt16  nStyle      = 0;
    2982             : 
    2983             :     // draw separators in flat style only
    2984      177046 :     if ( !bLayout &&
    2985      177046 :          (mnOutStyle & TOOLBOX_STYLE_FLAT) &&
    2986      110710 :          (pItem->meType == TOOLBOXITEM_SEPARATOR) &&
    2987       22187 :          nPos > 0
    2988             :          )
    2989             :     {
    2990       22187 :         ImplDrawSeparator( nPos, aButtonRect );
    2991             :     }
    2992             : 
    2993             :     // do nothing if item is no button or will be displayed as window
    2994       88523 :     if ( (pItem->meType != TOOLBOXITEM_BUTTON) ||
    2995        4198 :          (pItem->mbShowWindow && !mbCustomizeMode) )
    2996       26462 :         return;
    2997             : 
    2998             :     // we need a TBDragMananger to draw the configuration item
    2999             :     ImplTBDragMgr* pMgr;
    3000       62061 :     if ( pItem->mnId == mnConfigItem )
    3001             :     {
    3002           0 :         pMgr = ImplGetTBDragMgr();
    3003           0 :         pMgr->HideDragRect();
    3004             :     }
    3005             :     else
    3006       62061 :         pMgr = NULL;
    3007             : 
    3008             :     // during configuration mode visible windows will be drawn in a special way
    3009       62061 :     if ( mbCustomizeMode && pItem->mbShowWindow )
    3010             :     {
    3011           0 :         Font    aOldFont = GetFont();
    3012           0 :         Color   aOldTextColor = GetTextColor();
    3013             : 
    3014           0 :         SetZoomedPointFont( rStyleSettings.GetAppFont() );
    3015           0 :         SetLineColor( Color( COL_BLACK ) );
    3016           0 :         SetFillColor( rStyleSettings.GetFieldColor() );
    3017           0 :         SetTextColor( rStyleSettings.GetFieldTextColor() );
    3018           0 :         if( !bLayout )
    3019           0 :             DrawRect( pItem->maRect );
    3020             : 
    3021           0 :         Size aSize( GetCtrlTextWidth( pItem->maText ), GetTextHeight() );
    3022           0 :         Point aPos( pItem->maRect.Left()+2, pItem->maRect.Top() );
    3023           0 :         aPos.Y() += (pItem->maRect.GetHeight()-aSize.Height())/2;
    3024             :         bool bClip;
    3025           0 :         if ( (aSize.Width() > pItem->maRect.GetWidth()-2) ||
    3026           0 :              (aSize.Height() > pItem->maRect.GetHeight()-2) )
    3027             :         {
    3028           0 :             bClip = true;
    3029           0 :             Rectangle aTempRect( pItem->maRect.Left()+1, pItem->maRect.Top()+1,
    3030           0 :                                  pItem->maRect.Right()-1, pItem->maRect.Bottom()-1 );
    3031           0 :             Region aTempRegion( aTempRect );
    3032           0 :             SetClipRegion( aTempRegion );
    3033             :         }
    3034             :         else
    3035           0 :             bClip = false;
    3036           0 :         if( bLayout )
    3037             :         {
    3038           0 :             mpData->m_pLayoutData->m_aLineIndices.push_back( mpData->m_pLayoutData->m_aDisplayText.getLength() );
    3039           0 :             mpData->m_pLayoutData->m_aLineItemIds.push_back( pItem->mnId );
    3040           0 :             mpData->m_pLayoutData->m_aLineItemPositions.push_back( nPos );
    3041             :         }
    3042           0 :         DrawCtrlText( aPos, pItem->maText, 0, pItem->maText.getLength(), TEXT_DRAW_MNEMONIC, pVector, pDisplayText );
    3043           0 :         if ( bClip )
    3044           0 :             SetClipRegion();
    3045           0 :         SetFont( aOldFont );
    3046           0 :         SetTextColor( aOldTextColor );
    3047             : 
    3048             :         // draw Config-Frame if required
    3049           0 :         if ( pMgr && !bLayout)
    3050           0 :             pMgr->UpdateDragRect();
    3051           0 :         return;
    3052             :     }
    3053             : 
    3054       62061 :     if ( pItem->meState == TRISTATE_TRUE )
    3055             :     {
    3056        3722 :         nStyle |= BUTTON_DRAW_CHECKED;
    3057             :     }
    3058       58339 :     else if ( pItem->meState == TRISTATE_INDET )
    3059             :     {
    3060           5 :         nStyle |= BUTTON_DRAW_DONTKNOW;
    3061             :     }
    3062       62061 :     if ( nHighlight == 1 )
    3063             :     {
    3064           0 :         nStyle |= BUTTON_DRAW_PRESSED;
    3065             :     }
    3066             : 
    3067       62061 :     if( ! bLayout )
    3068             :     {
    3069       62061 :         if ( mnOutStyle & TOOLBOX_STYLE_FLAT )
    3070             :         {
    3071       62061 :             if ( (pItem->meState != TRISTATE_FALSE) || !bPaint )
    3072             :             {
    3073       62061 :                 ImplErase( this, pItem->maRect, nHighlight != 0, bHasOpenPopup );
    3074             :             }
    3075             :         }
    3076             :         else
    3077             :         {
    3078           0 :             DecorationView aDecoView( this );
    3079           0 :             aDecoView.DrawButton( aButtonRect, nStyle );
    3080             :         }
    3081             :     }
    3082             : 
    3083       62061 :     nOffX += pItem->maRect.Left();
    3084       62061 :     nOffY += pItem->maRect.Top();
    3085             : 
    3086             :     // determine what has to be drawn on the button: image, text or both
    3087             :     bool bImage;
    3088             :     bool bText;
    3089       62061 :     ButtonType tmpButtonType = determineButtonType( pItem, meButtonType ); // default to toolbox setting
    3090       62061 :     pItem->DetermineButtonDrawStyle( tmpButtonType, bImage, bText );
    3091             : 
    3092             :     // compute output values
    3093       62061 :     long    nBtnWidth = aBtnSize.Width()-SMALLBUTTON_HSIZE;
    3094       62061 :     long    nBtnHeight = aBtnSize.Height()-SMALLBUTTON_VSIZE;
    3095       62061 :     Size    aImageSize;
    3096       62061 :     Size    aTxtSize;
    3097             : 
    3098       62061 :     if ( bText )
    3099             :     {
    3100          60 :         aTxtSize.Width() = GetCtrlTextWidth( pItem->maText );
    3101          60 :         aTxtSize.Height() = GetTextHeight();
    3102             :     }
    3103             : 
    3104       62061 :     if ( bImage && ! bLayout )
    3105             :     {
    3106             :         const Image* pImage;
    3107       62001 :         if ( (nHighlight != 0) && !!(pItem->maHighImage) )
    3108           0 :             pImage = &(pItem->maHighImage);
    3109             :         else
    3110       62001 :             pImage = &(pItem->maImage);
    3111             : 
    3112       62001 :         aImageSize = pImage->GetSizePixel();
    3113             : 
    3114             :         // determine drawing flags
    3115       62001 :         sal_uInt16 nImageStyle = 0;
    3116             : 
    3117       62001 :         if ( !pItem->mbEnabled || !IsEnabled() )
    3118        7549 :             nImageStyle |= IMAGE_DRAW_DISABLE;
    3119             : 
    3120             :         // #i35563# the dontknow state indicates different states at the same time
    3121             :         // which should not be rendered disabled but normal
    3122             : 
    3123             :         // draw the image
    3124       62001 :         nImageOffX = nOffX;
    3125       62001 :         nImageOffY = nOffY;
    3126       62001 :         if ( (pItem->mnBits & (TIB_LEFT|TIB_DROPDOWN)) || bText )
    3127             :         {
    3128             :             // left align also to leave space for drop down arrow
    3129             :             // and when drawing text+image
    3130             :             // just center in y, except for vertical (ie rotated text)
    3131       26992 :             if( mbHorz || !bText )
    3132       13496 :                 nImageOffY += (nBtnHeight-aImageSize.Height())/2;
    3133             :         }
    3134             :         else
    3135             :         {
    3136       48505 :             nImageOffX += (nBtnWidth-aImageSize.Width())/2;
    3137       48505 :             nImageOffY += (nBtnHeight-aImageSize.Height())/2;
    3138             :         }
    3139       62001 :         if ( nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) )
    3140             :         {
    3141        3723 :             if( bHasOpenPopup )
    3142           0 :                 ImplDrawFloatwinBorder( pItem );
    3143             :             else
    3144        3723 :                 ImplDrawButton( this, aButtonRect, nHighlight, pItem->meState == TRISTATE_TRUE, pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow ? true : false );
    3145             : 
    3146        3723 :             if( nHighlight != 0 )
    3147             :             {
    3148           1 :                 if( bHighContrastWhite )
    3149           0 :                     nImageStyle |= IMAGE_DRAW_COLORTRANSFORM;
    3150             :             }
    3151             :         }
    3152       62001 :         DrawImage( Point( nImageOffX, nImageOffY ), *pImage, nImageStyle );
    3153             :     }
    3154             : 
    3155             :     // draw the text
    3156       62061 :     bool bRotate = false;
    3157       62061 :     if ( bText )
    3158             :     {
    3159          60 :         long nTextOffX = nOffX;
    3160          60 :         long nTextOffY = nOffY;
    3161             : 
    3162             :         // rotate text when vertically docked
    3163          60 :         Font aOldFont = GetFont();
    3164         120 :         if( pItem->mbVisibleText && !ImplIsFloatingMode() &&
    3165         120 :             ((meAlign == WINDOWALIGN_LEFT) || (meAlign == WINDOWALIGN_RIGHT)) )
    3166             :         {
    3167           0 :             bRotate = true;
    3168             : 
    3169           0 :             Font aRotateFont = aOldFont;
    3170           0 :             aRotateFont.SetOrientation( 2700 );
    3171             : 
    3172             :             // center horizontally
    3173           0 :             nTextOffX += aTxtSize.Height();
    3174           0 :             nTextOffX += (nBtnWidth-aTxtSize.Height())/2;
    3175             : 
    3176             :             // add in image offset
    3177           0 :             if( bImage )
    3178           0 :                 nTextOffY = nImageOffY + aImageSize.Height() + TB_IMAGETEXTOFFSET;
    3179             : 
    3180           0 :             SetFont( aRotateFont );
    3181             :         }
    3182             :         else
    3183             :         {
    3184             :             // center vertically
    3185          60 :             nTextOffY += (nBtnHeight-aTxtSize.Height())/2;
    3186             : 
    3187             :             // add in image offset
    3188          60 :             if( bImage )
    3189           0 :                 nTextOffX = nImageOffX + aImageSize.Width() + TB_IMAGETEXTOFFSET;
    3190             :         }
    3191             : 
    3192             :         // draw selection only if not already drawn during image output (see above)
    3193          60 :         if ( !bLayout && !bImage && (nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) ) )
    3194             :         {
    3195           0 :             if( bHasOpenPopup )
    3196           0 :                 ImplDrawFloatwinBorder( pItem );
    3197             :             else
    3198           0 :                 ImplDrawButton( this, pItem->maRect, nHighlight, pItem->meState == TRISTATE_TRUE, pItem->mbEnabled && IsEnabled(), pItem->mbShowWindow ? true : false );
    3199             :         }
    3200             : 
    3201          60 :         sal_uInt16 nTextStyle = 0;
    3202          60 :         if ( !pItem->mbEnabled )
    3203          17 :             nTextStyle |= TEXT_DRAW_DISABLE;
    3204          60 :         if( bLayout )
    3205             :         {
    3206           0 :             mpData->m_pLayoutData->m_aLineIndices.push_back( mpData->m_pLayoutData->m_aDisplayText.getLength() );
    3207           0 :             mpData->m_pLayoutData->m_aLineItemIds.push_back( pItem->mnId );
    3208           0 :             mpData->m_pLayoutData->m_aLineItemPositions.push_back( nPos );
    3209             :         }
    3210             :         DrawCtrlText( Point( nTextOffX, nTextOffY ), pItem->maText,
    3211          60 :                       0, pItem->maText.getLength(), nTextStyle, pVector, pDisplayText );
    3212          60 :         if ( bRotate )
    3213           0 :             SetFont( aOldFont );
    3214             :     }
    3215             : 
    3216       62061 :     if( bLayout )
    3217           0 :         return;
    3218             : 
    3219             :     // paint optional drop down arrow
    3220       62061 :     if ( pItem->mnBits & TIB_DROPDOWN )
    3221             :     {
    3222       13498 :         Rectangle aDropDownRect( pItem->GetDropDownRect( mbHorz ) );
    3223       13498 :         bool bSetColor = true;
    3224       13498 :         if ( !pItem->mbEnabled || !IsEnabled() )
    3225             :         {
    3226        2775 :             bSetColor = false;
    3227        2775 :             SetFillColor( rStyleSettings.GetShadowColor() );
    3228             :         }
    3229             : 
    3230             :         // dropdown only will be painted without inner border
    3231       13498 :         if( (pItem->mnBits & TIB_DROPDOWNONLY) != TIB_DROPDOWNONLY )
    3232             :         {
    3233       13113 :             ImplErase( this, aDropDownRect, nHighlight != 0, bHasOpenPopup );
    3234             : 
    3235       13113 :             if( nHighlight != 0 || (pItem->meState == TRISTATE_TRUE) )
    3236             :             {
    3237           0 :                 if( bHasOpenPopup )
    3238           0 :                     ImplDrawFloatwinBorder( pItem );
    3239             :                 else
    3240           0 :                     ImplDrawButton( this, aDropDownRect, nHighlight, pItem->meState == TRISTATE_TRUE, pItem->mbEnabled && IsEnabled(), false );
    3241             :             }
    3242             :         }
    3243       13498 :         ImplDrawDropdownArrow( this, aDropDownRect, bSetColor, bRotate );
    3244             :     }
    3245             : 
    3246             :     // draw config-frame if required
    3247       62061 :     if ( pMgr )
    3248           0 :         pMgr->UpdateDragRect();
    3249             : }
    3250             : 
    3251           0 : void ToolBox::ImplDrawFloatwinBorder( ImplToolItem* pItem )
    3252             : {
    3253           0 :     if ( !pItem->maRect.IsEmpty() )
    3254             :     {
    3255           0 :         Rectangle aRect( mpFloatWin->ImplGetItemEdgeClipRect() );
    3256           0 :         aRect.SetPos( AbsoluteScreenToOutputPixel( aRect.TopLeft() ) );
    3257           0 :         SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
    3258           0 :         Point p1, p2;
    3259             : 
    3260           0 :         p1 = pItem->maRect.TopLeft();
    3261           0 :         p1.X()++;
    3262           0 :         p2 = pItem->maRect.TopRight();
    3263           0 :         p2.X()--;
    3264           0 :         DrawLine( p1, p2);
    3265           0 :         p1 = pItem->maRect.BottomLeft();
    3266           0 :         p1.X()++;
    3267           0 :         p2 = pItem->maRect.BottomRight();
    3268           0 :         p2.X()--;
    3269           0 :         DrawLine( p1, p2);
    3270             : 
    3271           0 :         p1 = pItem->maRect.TopLeft();
    3272           0 :         p1.Y()++;
    3273           0 :         p2 = pItem->maRect.BottomLeft();
    3274           0 :         p2.Y()--;
    3275           0 :         DrawLine( p1, p2);
    3276           0 :         p1 = pItem->maRect.TopRight();
    3277           0 :         p1.Y()++;
    3278           0 :         p2 = pItem->maRect.BottomRight();
    3279           0 :         p2.Y()--;
    3280           0 :         DrawLine( p1, p2);
    3281             : 
    3282             :         //DrawRect( pItem->maRect );
    3283             :     }
    3284           0 : }
    3285             : 
    3286           0 : void ToolBox::ImplFloatControl( bool bStart, FloatingWindow* pFloatWindow )
    3287             : {
    3288             : 
    3289           0 :     if ( bStart )
    3290             :     {
    3291           0 :         mpFloatWin = pFloatWindow;
    3292             : 
    3293             :         // redraw item, to trigger drawing of a special border
    3294           0 :         ImplDrawItem( mnCurPos, 1 );
    3295             : 
    3296           0 :         mbDrag = false;
    3297           0 :         EndTracking();
    3298           0 :         ReleaseMouse();
    3299             :     }
    3300             :     else
    3301             :     {
    3302           0 :         mpFloatWin = NULL;
    3303             : 
    3304             :         // if focus is still in this toolbox, then the floater was opened by keyboard
    3305             :         // draw current item with highlight and keep old state
    3306           0 :         bool bWasKeyboardActivate = mpData->mbDropDownByKeyboard;
    3307             : 
    3308           0 :         if ( mnCurPos != TOOLBOX_ITEM_NOTFOUND )
    3309           0 :             ImplDrawItem( mnCurPos, bWasKeyboardActivate ? 2 : 0 );
    3310           0 :         Deactivate();
    3311             : 
    3312           0 :         if( !bWasKeyboardActivate )
    3313             :         {
    3314           0 :             mnCurPos = TOOLBOX_ITEM_NOTFOUND;
    3315           0 :             mnCurItemId = 0;
    3316           0 :             mnHighItemId = 0;
    3317             :         }
    3318           0 :         mnDownItemId = 0;
    3319             : 
    3320             :     }
    3321           0 : }
    3322             : 
    3323           0 : void ToolBox::ShowLine( bool bNext )
    3324             : {
    3325             : 
    3326           0 :     mbFormat = true;
    3327             : 
    3328           0 :     if ( mpData->mbPageScroll )
    3329             :     {
    3330           0 :         sal_uInt16 delta = mnVisLines;
    3331           0 :         if ( bNext )
    3332             :         {
    3333           0 :             mnCurLine = mnCurLine + delta;
    3334           0 :             if ( mnCurLine+mnVisLines-1 > mnCurLines )
    3335           0 :                 mnCurLine = mnCurLines - mnVisLines+1;
    3336             :         }
    3337             :         else
    3338             :         {
    3339           0 :             if( mnCurLine >= delta+1 )
    3340           0 :                 mnCurLine = mnCurLine - delta;
    3341             :             else
    3342           0 :                 mnCurLine = 1;
    3343             :         }
    3344             :     }
    3345             :     else
    3346             :     {
    3347           0 :         if ( bNext )
    3348           0 :             mnCurLine++;
    3349             :         else
    3350           0 :             mnCurLine--;
    3351             :     }
    3352             : 
    3353           0 :     ImplFormat();
    3354           0 : }
    3355             : 
    3356           0 : bool ToolBox::ImplHandleMouseMove( const MouseEvent& rMEvt, bool bRepeat )
    3357             : {
    3358           0 :     Point aMousePos = rMEvt.GetPosPixel();
    3359             : 
    3360             :     // ToolBox active?
    3361           0 :     if ( mbDrag && mnCurPos != TOOLBOX_ITEM_NOTFOUND )
    3362             :     {
    3363             :         // is the cursor over the item?
    3364           0 :         ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
    3365           0 :         if ( pItem->maRect.IsInside( aMousePos ) )
    3366             :         {
    3367           0 :             if ( !mnCurItemId )
    3368             :             {
    3369           0 :                 ImplDrawItem( mnCurPos, 1 );
    3370           0 :                 mnCurItemId = pItem->mnId;
    3371           0 :                 Highlight();
    3372             :             }
    3373             : 
    3374           0 :             if ( (pItem->mnBits & TIB_REPEAT) && bRepeat )
    3375           0 :                 Select();
    3376             :         }
    3377             :         else
    3378             :         {
    3379           0 :             if ( mnCurItemId )
    3380             :             {
    3381           0 :                 ImplDrawItem( mnCurPos );
    3382           0 :                 mnCurItemId = 0;
    3383           0 :                 ImplDrawItem( mnCurPos );
    3384           0 :                 Highlight();
    3385             :             }
    3386             :         }
    3387             : 
    3388           0 :         return true;
    3389             :     }
    3390             : 
    3391           0 :     if ( mbUpper )
    3392             :     {
    3393           0 :         bool bNewIn = maUpperRect.IsInside( aMousePos );
    3394           0 :         if ( bNewIn != mbIn )
    3395             :         {
    3396           0 :             mbIn = bNewIn;
    3397           0 :             ImplDrawSpin( mbIn, false );
    3398             :         }
    3399           0 :         return true;
    3400             :     }
    3401             : 
    3402           0 :     if ( mbLower )
    3403             :     {
    3404           0 :         bool bNewIn = maLowerRect.IsInside( aMousePos );
    3405           0 :         if ( bNewIn != mbIn )
    3406             :         {
    3407           0 :             mbIn = bNewIn;
    3408           0 :             ImplDrawSpin( false, mbIn );
    3409             :         }
    3410           0 :         return true;
    3411             :     }
    3412             : 
    3413           0 :     return false;
    3414             : }
    3415             : 
    3416           0 : bool ToolBox::ImplHandleMouseButtonUp( const MouseEvent& rMEvt, bool bCancel )
    3417             : {
    3418           0 :     ImplDisableFlatButtons();
    3419             : 
    3420             :     // stop eventual running dropdown timer
    3421           0 :     if( mnCurPos < mpData->m_aItems.size() &&
    3422           0 :         (mpData->m_aItems[mnCurPos].mnBits & TIB_DROPDOWN ) )
    3423             :     {
    3424           0 :         mpData->maDropdownTimer.Stop();
    3425             :     }
    3426             : 
    3427           0 :     if ( mbDrag || mbSelection )
    3428             :     {
    3429             :         // set mouse data if in selection mode, as then
    3430             :         // the MouseButtonDown handler cannot be called
    3431           0 :         if ( mbSelection )
    3432             :         {
    3433           0 :             mnMouseClicks    = rMEvt.GetClicks();
    3434           0 :             mnMouseModifier  = rMEvt.GetModifier();
    3435             :         }
    3436             : 
    3437           0 :         Deactivate();
    3438             : 
    3439           0 :         if ( mbDrag )
    3440           0 :             mbDrag = false;
    3441             :         else
    3442             :         {
    3443           0 :             mbSelection = false;
    3444           0 :             if ( mnCurPos == TOOLBOX_ITEM_NOTFOUND )
    3445           0 :                 return true;
    3446             :         }
    3447             : 
    3448             :         // has mouse been released on top of item?
    3449           0 :         if( mnCurPos < mpData->m_aItems.size() )
    3450             :         {
    3451           0 :             ImplToolItem* pItem = &mpData->m_aItems[mnCurPos];
    3452           0 :             if ( pItem->maRect.IsInside( rMEvt.GetPosPixel() ) )
    3453             :             {
    3454           0 :                 mnCurItemId = pItem->mnId;
    3455           0 :                 if ( !bCancel )
    3456             :                 {
    3457             :                     // execute AutoCheck if required
    3458           0 :                     if ( pItem->mnBits & TIB_AUTOCHECK )
    3459             :                     {
    3460           0 :                         if ( pItem->mnBits & TIB_RADIOCHECK )
    3461             :                         {
    3462           0 :                             if ( pItem->meState != TRISTATE_TRUE )
    3463           0 :                                 SetItemState( pItem->mnId, TRISTATE_TRUE );
    3464             :                         }
    3465             :                         else
    3466             :                         {
    3467           0 :                             if ( pItem->meState != TRISTATE_TRUE )
    3468           0 :                                 pItem->meState = TRISTATE_TRUE;
    3469             :                             else
    3470           0 :                                 pItem->meState = TRISTATE_FALSE;
    3471             :                         }
    3472             :                     }
    3473             : 
    3474             :                     // do not call Select when Repeat is active, as in this
    3475             :                     // case that was triggered already in MouseButtonDown
    3476           0 :                     if ( !(pItem->mnBits & TIB_REPEAT) )
    3477             :                     {
    3478             :                         // prevent from being destroyed in the select handler
    3479           0 :                         ImplDelData aDelData;
    3480           0 :                         ImplAddDel( &aDelData );
    3481           0 :                         Select();
    3482           0 :                         if ( aDelData.IsDead() )
    3483           0 :                             return true;
    3484           0 :                         ImplRemoveDel( &aDelData );
    3485             :                     }
    3486             :                 }
    3487             : 
    3488             :                 {
    3489             :                 }
    3490             : 
    3491             :                 // Items not destroyed, in Select handler
    3492           0 :                 if ( mnCurItemId )
    3493             :                 {
    3494             :                     sal_uInt16 nHighlight;
    3495           0 :                     if ( (mnCurItemId == mnHighItemId) && (mnOutStyle & TOOLBOX_STYLE_FLAT) )
    3496           0 :                         nHighlight = 2;
    3497             :                     else
    3498           0 :                         nHighlight = 0;
    3499             :                     // Get current pos for the case that items are inserted/removed
    3500             :                     // in the toolBox
    3501           0 :                     mnCurPos = GetItemPos( mnCurItemId );
    3502           0 :                     if ( mnCurPos != TOOLBOX_ITEM_NOTFOUND )
    3503             :                     {
    3504           0 :                         ImplDrawItem( mnCurPos, nHighlight );
    3505           0 :                         Flush();
    3506             :                     }
    3507             :                 }
    3508             :             }
    3509             :         }
    3510             : 
    3511           0 :         mnCurPos         = TOOLBOX_ITEM_NOTFOUND;
    3512           0 :         mnCurItemId      = 0;
    3513           0 :         mnDownItemId     = 0;
    3514           0 :         mnMouseClicks    = 0;
    3515           0 :         mnMouseModifier  = 0;
    3516           0 :         return true;
    3517             :     }
    3518           0 :     else if ( mbUpper || mbLower )
    3519             :     {
    3520           0 :         if ( mbIn )
    3521           0 :             ShowLine( !mbUpper );
    3522           0 :         mbUpper = false;
    3523           0 :         mbLower = false;
    3524           0 :         mbIn    = false;
    3525           0 :         ImplDrawSpin( false, false );
    3526           0 :         return true;
    3527             :     }
    3528             : 
    3529           0 :     return false;
    3530             : }
    3531             : 
    3532           0 : void ToolBox::MouseMove( const MouseEvent& rMEvt )
    3533             : {
    3534             :     // pressing a modifier generates synthetic mouse moves
    3535             :     // ignore it if keyboard selection is acive
    3536           0 :     if( HasFocus() && ( rMEvt.GetMode() & MOUSE_MODIFIERCHANGED ) )
    3537           0 :         return;
    3538             : 
    3539           0 :     if ( ImplHandleMouseMove( rMEvt ) )
    3540           0 :         return;
    3541             : 
    3542           0 :     ImplDisableFlatButtons();
    3543             : 
    3544           0 :     Point aMousePos = rMEvt.GetPosPixel();
    3545             : 
    3546             :     // only highlight when the focus is not inside a child window of a toolbox
    3547             :     // eg, in a edit control
    3548             :     // and do not hilight when focus is in a different toolbox
    3549           0 :     bool bDrawHotSpot = true;
    3550           0 :     Window *pWin = Application::GetFocusWindow();
    3551           0 :     if( pWin && pWin->ImplGetWindowImpl()->mbToolBox && pWin != this )
    3552           0 :         bDrawHotSpot = false;
    3553             : 
    3554           0 :     if ( mbSelection && bDrawHotSpot )
    3555             :     {
    3556           0 :         sal_uInt16  i = 0;
    3557           0 :         sal_uInt16  nNewPos = TOOLBOX_ITEM_NOTFOUND;
    3558             : 
    3559             :         // search the item that has been clicked
    3560           0 :         std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
    3561           0 :         while ( it != mpData->m_aItems.end() )
    3562             :         {
    3563             :             // if the mouse position is in this item,
    3564             :             // we can stop the search
    3565           0 :             if ( it->maRect.IsInside( aMousePos ) )
    3566             :             {
    3567             :                 // select it if it is a button
    3568           0 :                 if ( it->meType == TOOLBOXITEM_BUTTON )
    3569             :                 {
    3570             :                     // if button is disabled, do not
    3571             :                     // change it
    3572           0 :                     if ( !it->mbEnabled || it->mbShowWindow )
    3573           0 :                         nNewPos = mnCurPos;
    3574             :                     else
    3575           0 :                         nNewPos = i;
    3576             :                 }
    3577             : 
    3578           0 :                 break;
    3579             :             }
    3580             : 
    3581           0 :             i++;
    3582           0 :             ++it;
    3583             :         }
    3584             : 
    3585             :         // was a new entery selected ?
    3586             :         // don't  change selection if keyboard selection is active and
    3587             :         // mouse leaves the toolbox
    3588           0 :         if ( nNewPos != mnCurPos && !( HasFocus() && nNewPos == TOOLBOX_ITEM_NOTFOUND ) )
    3589             :         {
    3590           0 :             if ( mnCurPos != TOOLBOX_ITEM_NOTFOUND )
    3591             :             {
    3592           0 :                 ImplDrawItem( mnCurPos );
    3593           0 :                 ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHTOFF, reinterpret_cast< void* >( mnCurPos ) );
    3594             :             }
    3595             : 
    3596           0 :             mnCurPos = nNewPos;
    3597           0 :             if ( mnCurPos != TOOLBOX_ITEM_NOTFOUND )
    3598             :             {
    3599           0 :                 mnCurItemId = mnHighItemId = it->mnId;
    3600           0 :                 ImplDrawItem( mnCurPos, 2 ); // always use shadow effect (2)
    3601             :             }
    3602             :             else
    3603           0 :                 mnCurItemId = mnHighItemId = 0;
    3604             : 
    3605           0 :             Highlight();
    3606             :         }
    3607           0 :         return;
    3608             :     }
    3609             : 
    3610           0 :     if ( mbDragging )
    3611             :     {
    3612           0 :         ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
    3613           0 :         pMgr->Dragging( aMousePos );
    3614           0 :         return;
    3615             :     }
    3616             : 
    3617           0 :     PointerStyle eStyle = POINTER_ARROW;
    3618             : 
    3619             :     // change mouse cursor over drag area
    3620           0 :     ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
    3621           0 :     if( pWrapper && pWrapper->GetDragArea().IsInside( rMEvt.GetPosPixel() ) )
    3622           0 :         eStyle = POINTER_MOVE;
    3623             : 
    3624           0 :     if ( (mnWinStyle & TB_WBLINESIZING) == TB_WBLINESIZING )
    3625             :     {
    3626           0 :         if ( rMEvt.GetMode() & MOUSE_SIMPLEMOVE )
    3627             :         {
    3628           0 :             sal_uInt16 nLinePtr = ImplTestLineSize( this, rMEvt.GetPosPixel() );
    3629           0 :             if ( nLinePtr & DOCK_LINEHSIZE )
    3630             :             {
    3631           0 :                 if ( meAlign == WINDOWALIGN_LEFT )
    3632           0 :                     eStyle = POINTER_WINDOW_ESIZE;
    3633             :                 else
    3634           0 :                     eStyle = POINTER_WINDOW_WSIZE;
    3635             :             }
    3636           0 :             else if ( nLinePtr & DOCK_LINEVSIZE )
    3637             :             {
    3638           0 :                 if ( meAlign == WINDOWALIGN_TOP )
    3639           0 :                     eStyle = POINTER_WINDOW_SSIZE;
    3640             :                 else
    3641           0 :                     eStyle = POINTER_WINDOW_NSIZE;
    3642             :             }
    3643             :         }
    3644             :     }
    3645             : 
    3646           0 :     if ( (eStyle == POINTER_ARROW) && mbCustomizeMode )
    3647             :     {
    3648             :         // search the item which was clicked
    3649           0 :         std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
    3650           0 :         while ( it != mpData->m_aItems.end() )
    3651             :         {
    3652             :             // show resize pointer if it is a customize window
    3653           0 :             if ( it->mbShowWindow )
    3654             :             {
    3655           0 :                 if ( it->maRect.IsInside( aMousePos ) )
    3656             :                 {
    3657           0 :                     if ( it->maRect.Right()-TB_RESIZE_OFFSET <= aMousePos.X() )
    3658           0 :                         eStyle = POINTER_HSIZEBAR;
    3659           0 :                     break;
    3660             :                 }
    3661             :             }
    3662             : 
    3663           0 :             ++it;
    3664             :         }
    3665             :     }
    3666             : 
    3667           0 :     if ( bDrawHotSpot && ( (mnOutStyle & TOOLBOX_STYLE_FLAT) || !mnOutStyle ) )
    3668             :     {
    3669           0 :         bool bClearHigh = true;
    3670           0 :         if ( !rMEvt.IsLeaveWindow() && (mnCurPos == TOOLBOX_ITEM_NOTFOUND) )
    3671             :         {
    3672           0 :             std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
    3673           0 :             while ( it != mpData->m_aItems.end() )
    3674             :             {
    3675           0 :                 if ( it->maRect.IsInside( aMousePos ) )
    3676             :                 {
    3677           0 :                     if ( (it->meType == TOOLBOXITEM_BUTTON) && it->mbEnabled )
    3678             :                     {
    3679           0 :                         if ( !mnOutStyle || (mnOutStyle & TOOLBOX_STYLE_FLAT) )
    3680             :                         {
    3681           0 :                             bClearHigh = false;
    3682           0 :                             if ( mnHighItemId != it->mnId )
    3683             :                             {
    3684           0 :                                 sal_uInt16 nTempPos = sal::static_int_cast<sal_uInt16>(it - mpData->m_aItems.begin());
    3685           0 :                                 if ( mnHighItemId )
    3686             :                                 {
    3687           0 :                                     ImplHideFocus();
    3688           0 :                                     sal_uInt16 nPos = GetItemPos( mnHighItemId );
    3689           0 :                                     ImplDrawItem( nPos );
    3690           0 :                                     ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHTOFF, reinterpret_cast< void* >( nPos ) );
    3691             :                                 }
    3692           0 :                                 if ( mpData->mbMenubuttonSelected )
    3693             :                                 {
    3694             :                                     // remove highlight from menubutton
    3695           0 :                                     ImplDrawMenubutton( this, false );
    3696             :                                 }
    3697           0 :                                 mnHighItemId = it->mnId;
    3698           0 :                                 ImplDrawItem( nTempPos, 2 );
    3699           0 :                                 ImplShowFocus();
    3700           0 :                                 ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHT );
    3701             :                             }
    3702             :                         }
    3703             :                     }
    3704           0 :                     break;
    3705             :                 }
    3706             : 
    3707           0 :                 ++it;
    3708             :             }
    3709             :         }
    3710             : 
    3711             :         // only clear highlight when focus is not in toolbar
    3712           0 :         bool bMenuButtonHit = mpData->maMenubuttonItem.maRect.IsInside( aMousePos ) && ImplHasClippedItems();
    3713           0 :         if ( bClearHigh || bMenuButtonHit )
    3714             :         {
    3715           0 :             if ( !bMenuButtonHit && mpData->mbMenubuttonSelected )
    3716             :             {
    3717             :                 // remove highlight from menubutton
    3718           0 :                 ImplDrawMenubutton( this, false );
    3719             :             }
    3720             : 
    3721           0 :             if( mnHighItemId )
    3722             :             {
    3723           0 :                 sal_uInt16 nClearPos = GetItemPos( mnHighItemId );
    3724           0 :                 if ( nClearPos != TOOLBOX_ITEM_NOTFOUND )
    3725             :                 {
    3726           0 :                     ImplDrawItem( nClearPos, (nClearPos == mnCurPos) ? 1 : 0 );
    3727           0 :                     if( nClearPos != mnCurPos )
    3728           0 :                         ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHTOFF, reinterpret_cast< void* >( nClearPos ) );
    3729             :                 }
    3730           0 :                 ImplHideFocus();
    3731           0 :                 mnHighItemId = 0;
    3732             :             }
    3733             : 
    3734           0 :             if( bMenuButtonHit )
    3735             :             {
    3736           0 :                 ImplDrawMenubutton( this, true );
    3737             :             }
    3738             :         }
    3739             :     }
    3740             : 
    3741           0 :     if ( meLastStyle != eStyle )
    3742             :     {
    3743           0 :         meLastStyle = eStyle;
    3744           0 :         Pointer aPtr( eStyle );
    3745           0 :         SetPointer( aPtr );
    3746             :     }
    3747             : 
    3748           0 :     DockingWindow::MouseMove( rMEvt );
    3749             : }
    3750             : 
    3751           0 : void ToolBox::MouseButtonDown( const MouseEvent& rMEvt )
    3752             : {
    3753             :     // only trigger toolbox for left mouse button and when
    3754             :     // we're not in normal operation
    3755           0 :     if ( rMEvt.IsLeft() && !mbDrag && (mnCurPos == TOOLBOX_ITEM_NOTFOUND) )
    3756             :     {
    3757             :         // call activate already here, as items could
    3758             :         // be exchanged
    3759           0 :         Activate();
    3760             : 
    3761             :         // update ToolBox here, such that user knows it
    3762           0 :         if ( mbFormat )
    3763             :         {
    3764           0 :             ImplFormat();
    3765           0 :             Update();
    3766             :         }
    3767             : 
    3768           0 :         Point  aMousePos = rMEvt.GetPosPixel();
    3769           0 :         sal_uInt16 i = 0;
    3770           0 :         sal_uInt16 nNewPos = TOOLBOX_ITEM_NOTFOUND;
    3771             : 
    3772             :         // search for item that was clicked
    3773           0 :         std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
    3774           0 :         while ( it != mpData->m_aItems.end() )
    3775             :         {
    3776             :             // is this the item?
    3777           0 :             if ( it->maRect.IsInside( aMousePos ) )
    3778             :             {
    3779             :                 // do nothing if it is a separator or
    3780             :                 // if the item has been disabled
    3781           0 :                 if ( (it->meType == TOOLBOXITEM_BUTTON) &&
    3782           0 :                      (!it->mbShowWindow || mbCustomizeMode) )
    3783           0 :                     nNewPos = i;
    3784             : 
    3785           0 :                 break;
    3786             :             }
    3787             : 
    3788           0 :             i++;
    3789           0 :             ++it;
    3790             :         }
    3791             : 
    3792             :         // item found
    3793           0 :         if ( nNewPos != TOOLBOX_ITEM_NOTFOUND )
    3794             :         {
    3795           0 :             if ( mbCustomize )
    3796             :             {
    3797           0 :                 if ( rMEvt.IsMod2() || mbCustomizeMode )
    3798             :                 {
    3799           0 :                     Deactivate();
    3800             : 
    3801           0 :                     ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
    3802           0 :                     Rectangle aItemRect = GetItemRect( it->mnId );
    3803           0 :                     mnConfigItem = it->mnId;
    3804             : 
    3805             :                     bool bResizeItem;
    3806           0 :                     if ( mbCustomizeMode && it->mbShowWindow &&
    3807           0 :                          (it->maRect.Right()-TB_RESIZE_OFFSET <= aMousePos.X()) )
    3808           0 :                         bResizeItem = true;
    3809             :                     else
    3810           0 :                         bResizeItem = false;
    3811           0 :                     pMgr->StartDragging( this, aMousePos, aItemRect, 0, bResizeItem );
    3812           0 :                     return;
    3813             :                 }
    3814             :             }
    3815             : 
    3816           0 :             if ( !it->mbEnabled )
    3817             :             {
    3818           0 :                 Deactivate();
    3819           0 :                 return;
    3820             :             }
    3821             : 
    3822             :             // update actual data
    3823           0 :             sal_uInt16 nTrackFlags = 0;
    3824           0 :             mnCurPos         = i;
    3825           0 :             mnCurItemId      = it->mnId;
    3826           0 :             mnDownItemId     = mnCurItemId;
    3827           0 :             mnMouseClicks    = rMEvt.GetClicks();
    3828           0 :             mnMouseModifier  = rMEvt.GetModifier();
    3829           0 :             if ( it->mnBits & TIB_REPEAT )
    3830           0 :                 nTrackFlags |= STARTTRACK_BUTTONREPEAT;
    3831             : 
    3832           0 :             if ( mbSelection )
    3833             :             {
    3834           0 :                 ImplDrawItem( mnCurPos, 1 );
    3835           0 :                 Highlight();
    3836             :             }
    3837             :             else
    3838             :             {
    3839             :                 // update bDrag here, as it is evaluated in the EndSelection
    3840           0 :                 mbDrag = true;
    3841             : 
    3842             :                 // on double-click: only call the handler, but do so before the button
    3843             :                 // is hit, as in the handler dragging
    3844             :                 // can be terminated
    3845           0 :                 if ( rMEvt.GetClicks() == 2 )
    3846           0 :                     DoubleClick();
    3847             : 
    3848           0 :                 if ( mbDrag )
    3849             :                 {
    3850           0 :                     ImplDrawItem( mnCurPos, 1 );
    3851           0 :                     Highlight();
    3852             :                 }
    3853             : 
    3854             :                 // was dropdown arrow pressed
    3855           0 :                 if( (it->mnBits & TIB_DROPDOWN) )
    3856             :                 {
    3857           0 :                     if( ( (it->mnBits & TIB_DROPDOWNONLY) == TIB_DROPDOWNONLY) || it->GetDropDownRect( mbHorz ).IsInside( aMousePos ))
    3858             :                     {
    3859             :                         // dropdownonly always triggers the dropdown handler, over the whole button area
    3860             : 
    3861             :                         // the drop down arrow should not trigger the item action
    3862           0 :                         mpData->mbDropDownByKeyboard = false;
    3863           0 :                         GetDropdownClickHdl().Call( this );
    3864             : 
    3865             :                         // do not reset data if the dropdown handler opened a floating window
    3866             :                         // see ImplFloatControl()
    3867           0 :                         if( mpFloatWin == NULL )
    3868             :                         {
    3869             :                             // no floater was opened
    3870           0 :                             Deactivate();
    3871           0 :                             ImplDrawItem( mnCurPos, 0 );
    3872             : 
    3873           0 :                             mnCurPos         = TOOLBOX_ITEM_NOTFOUND;
    3874           0 :                             mnCurItemId      = 0;
    3875           0 :                             mnDownItemId     = 0;
    3876           0 :                             mnMouseClicks    = 0;
    3877           0 :                             mnMouseModifier  = 0;
    3878           0 :                             mnHighItemId     = 0;
    3879             :                         }
    3880           0 :                         return;
    3881             :                     }
    3882             :                     else // activate long click timer
    3883           0 :                         mpData->maDropdownTimer.Start();
    3884             :                 }
    3885             : 
    3886             :                 // call Click handler
    3887           0 :                 if ( rMEvt.GetClicks() != 2 )
    3888           0 :                     Click();
    3889             : 
    3890             :                 // also call Select handler at repeat
    3891           0 :                 if ( nTrackFlags & STARTTRACK_BUTTONREPEAT )
    3892           0 :                     Select();
    3893             : 
    3894             :                 // if the actions was not aborted in Click handler
    3895           0 :                 if ( mbDrag )
    3896           0 :                     StartTracking( nTrackFlags );
    3897             :             }
    3898             : 
    3899             :             // if mouse was clicked over an item we
    3900             :             // can abort here
    3901           0 :             return;
    3902             :         }
    3903             : 
    3904           0 :         Deactivate();
    3905             : 
    3906             :         // menu button hit ?
    3907           0 :         if( mpData->maMenubuttonItem.maRect.IsInside( aMousePos ) && ImplHasClippedItems() )
    3908             :         {
    3909           0 :             ExecuteCustomMenu();
    3910           0 :             return;
    3911             :         }
    3912             : 
    3913             :         // check scroll- and next-buttons here
    3914           0 :         if ( maUpperRect.IsInside( aMousePos ) )
    3915             :         {
    3916           0 :             if ( mnCurLine > 1 )
    3917             :             {
    3918           0 :                 StartTracking();
    3919           0 :                 mbUpper = true;
    3920           0 :                 mbIn    = true;
    3921           0 :                 ImplDrawSpin( true, false );
    3922             :             }
    3923           0 :             return;
    3924             :         }
    3925           0 :         if ( maLowerRect.IsInside( aMousePos ) )
    3926             :         {
    3927           0 :             if ( mnCurLine+mnVisLines-1 < mnCurLines )
    3928             :             {
    3929           0 :                 StartTracking();
    3930           0 :                 mbLower = true;
    3931           0 :                 mbIn    = true;
    3932           0 :                 ImplDrawSpin( false, true );
    3933             :             }
    3934           0 :             return;
    3935             :         }
    3936             : 
    3937             :         // Linesizing testen
    3938           0 :         if ( (mnWinStyle & TB_WBLINESIZING) == TB_WBLINESIZING )
    3939             :         {
    3940           0 :             sal_uInt16 nLineMode = ImplTestLineSize( this, aMousePos );
    3941           0 :             if ( nLineMode )
    3942             :             {
    3943           0 :                 ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
    3944             : 
    3945             :                 // call handler, such that we can set the
    3946             :                 // dock rectangles
    3947           0 :                 StartDocking();
    3948             : 
    3949           0 :                 Point aPos  = GetParent()->OutputToScreenPixel( GetPosPixel() );
    3950           0 :                 Size  aSize = GetSizePixel();
    3951           0 :                 aPos = ScreenToOutputPixel( aPos );
    3952             : 
    3953             :                 // start dragging
    3954             :                 pMgr->StartDragging( this, aMousePos, Rectangle( aPos, aSize ),
    3955           0 :                                      nLineMode, false );
    3956           0 :                 return;
    3957             :             }
    3958             :         }
    3959             : 
    3960             :         // no item, then only click or double click
    3961           0 :         if ( rMEvt.GetClicks() == 2 )
    3962           0 :             DoubleClick();
    3963             :         else
    3964           0 :             Click();
    3965             :     }
    3966             : 
    3967           0 :     if ( !mbDrag && !mbSelection && (mnCurPos == TOOLBOX_ITEM_NOTFOUND) )
    3968           0 :         DockingWindow::MouseButtonDown( rMEvt );
    3969             : }
    3970             : 
    3971           0 : void ToolBox::MouseButtonUp( const MouseEvent& rMEvt )
    3972             : {
    3973           0 :     if ( ImplHandleMouseButtonUp( rMEvt ) )
    3974           0 :         return;
    3975             : 
    3976           0 :     if ( mbDragging && (rMEvt.IsLeft() || mbCommandDrag) )
    3977             :     {
    3978           0 :         ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
    3979           0 :         pMgr->EndDragging();
    3980           0 :         return;
    3981             :     }
    3982           0 :     mbCommandDrag = false;
    3983             : 
    3984           0 :     DockingWindow::MouseButtonUp( rMEvt );
    3985             : }
    3986             : 
    3987           0 : void ToolBox::Tracking( const TrackingEvent& rTEvt )
    3988             : {
    3989           0 :     ImplDelData aDelData;
    3990           0 :     ImplAddDel( &aDelData );
    3991             : 
    3992           0 :     if ( rTEvt.IsTrackingEnded() )
    3993           0 :         ImplHandleMouseButtonUp( rTEvt.GetMouseEvent(), rTEvt.IsTrackingCanceled() );
    3994             :     else
    3995           0 :         ImplHandleMouseMove( rTEvt.GetMouseEvent(), rTEvt.IsTrackingRepeat() );
    3996             : 
    3997           0 :     if ( aDelData.IsDead() )
    3998             :         // toolbox was deleted
    3999           0 :         return;
    4000           0 :     ImplRemoveDel( &aDelData );
    4001           0 :     DockingWindow::Tracking( rTEvt );
    4002             : }
    4003             : 
    4004       10054 : void ToolBox::Paint( const Rectangle& rPaintRect )
    4005             : {
    4006       10054 :     if( mpData->mbIsPaintLocked )
    4007       10054 :         return;
    4008       10054 :     if ( rPaintRect == Rectangle( 0, 0, mnDX-1, mnDY-1 ) )
    4009        8274 :         mbFullPaint = true;
    4010       10054 :     ImplFormat();
    4011       10054 :     mbFullPaint = false;
    4012             : 
    4013       10054 :     ImplDrawBackground( this, rPaintRect );
    4014             : 
    4015       10054 :     if ( (mnWinStyle & WB_BORDER) && !ImplIsFloatingMode() )
    4016        8288 :         ImplDrawBorder( this );
    4017             : 
    4018       10054 :     if( !ImplIsFloatingMode() )
    4019       10054 :         ImplDrawGrip( this );
    4020             : 
    4021       10054 :     ImplDrawMenubutton( this, mpData->mbMenubuttonSelected );
    4022             : 
    4023             :     // draw SpinButtons
    4024       10054 :     if ( mnWinStyle & WB_SCROLL )
    4025             :     {
    4026        8288 :         if ( mnCurLines > mnLines )
    4027           0 :             ImplDrawSpin( false, false );
    4028             :     }
    4029             : 
    4030             :     // draw buttons
    4031             :     sal_uInt16 nHighPos;
    4032       10054 :     if ( mnHighItemId )
    4033           0 :         nHighPos = GetItemPos( mnHighItemId );
    4034             :     else
    4035       10054 :         nHighPos = TOOLBOX_ITEM_NOTFOUND;
    4036             : 
    4037       10054 :     sal_uInt16 nCount = (sal_uInt16)mpData->m_aItems.size();
    4038      165729 :     for( sal_uInt16 i = 0; i < nCount; i++ )
    4039             :     {
    4040      155675 :         ImplToolItem* pItem = &mpData->m_aItems[i];
    4041             : 
    4042             :         // only draw when the rectangle is in the draw rectangle
    4043      155675 :         if ( !pItem->maRect.IsEmpty() && rPaintRect.IsOver( pItem->maRect ) )
    4044             :         {
    4045       88522 :             sal_uInt16 nHighlight = 0;
    4046       88522 :             if ( i == mnCurPos )
    4047           0 :                 nHighlight = 1;
    4048       88522 :             else if ( i == nHighPos )
    4049           0 :                 nHighlight = 2;
    4050       88522 :             ImplDrawItem( i, nHighlight );
    4051             :         }
    4052             :     }
    4053       10054 :     ImplShowFocus();
    4054             : }
    4055             : 
    4056        9636 : void ToolBox::Move()
    4057             : {
    4058        9636 :     DockingWindow::Move();
    4059        9636 : }
    4060             : 
    4061       10759 : void ToolBox::Resize()
    4062             : {
    4063       10759 :     Size aSize = GetOutputSizePixel();
    4064             :     // #i31422# some WindowManagers send (0,0) sizes when
    4065             :     // switching virtual desktops - ignore this and avoid reformatting
    4066       10759 :     if( !aSize.Width() && !aSize.Height() )
    4067       13039 :         return;
    4068             : 
    4069        8479 :     long nOldDX = mnDX;
    4070        8479 :     long nOldDY = mnDY;
    4071        8479 :     mnDX = aSize.Width();
    4072        8479 :     mnDY = aSize.Height();
    4073             : 
    4074        8479 :     mnLastResizeDY = 0;
    4075             : 
    4076             :     // invalidate everything to have gradient backgrounds properly drawn
    4077        8479 :     Invalidate();
    4078             : 
    4079             :     // If we have any expandable entries, then force a reformat first using
    4080             :     // their optimal sizes, then share out the excess space evenly across those
    4081             :     // expandables and reformat again
    4082        8479 :     std::vector<size_t> aExpandables;
    4083       95857 :     for (size_t i = 0; i < mpData->m_aItems.size(); ++i)
    4084             :     {
    4085       87378 :         if (mpData->m_aItems[i].mbExpand)
    4086             :         {
    4087           0 :             Window *pWindow = mpData->m_aItems[i].mpWindow;
    4088             :             SAL_WARN_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment");
    4089           0 :             if (!pWindow)
    4090           0 :                 continue;
    4091           0 :             Size aWinSize(pWindow->GetSizePixel());
    4092           0 :             Size aPrefSize(pWindow->get_preferred_size());
    4093           0 :             aWinSize.Width() = aPrefSize.Width();
    4094           0 :             pWindow->SetSizePixel(aWinSize);
    4095           0 :             aExpandables.push_back(i);
    4096             :         }
    4097             :     }
    4098             : 
    4099             :     // re-format or re-draw
    4100        8479 :     if ( mbScroll || !aExpandables.empty() )
    4101             :     {
    4102        4776 :         if ( !mbFormat || !aExpandables.empty() )
    4103             :         {
    4104         968 :             mbFormat = true;
    4105         968 :             if( IsReallyVisible() || !aExpandables.empty() )
    4106             :             {
    4107         406 :                 ImplFormat(true);
    4108             : 
    4109         406 :                 if (!aExpandables.empty())
    4110             :                 {
    4111             :                     //Get how big the optimal size is
    4112           0 :                     Rectangle aBounds;
    4113           0 :                     for (size_t i = 0; i < mpData->m_aItems.size(); ++i)
    4114             :                     {
    4115           0 :                         aBounds.Union( mpData->m_aItems[i].maRect );
    4116             :                     }
    4117             : 
    4118           0 :                     long nOptimalWidth = aBounds.GetWidth();
    4119           0 :                     long nDiff = aSize.Width() - nOptimalWidth;
    4120           0 :                     nDiff /= aExpandables.size();
    4121             : 
    4122             :                     //share out the diff from optimal to real across
    4123             :                     //expandable entries
    4124           0 :                     for (size_t i = 0; i < aExpandables.size(); ++i)
    4125             :                     {
    4126           0 :                         size_t nIndex = aExpandables[i];
    4127           0 :                         Window *pWindow = mpData->m_aItems[nIndex].mpWindow;
    4128           0 :                         Size aWinSize(pWindow->GetSizePixel());
    4129           0 :                         Size aPrefSize(pWindow->get_preferred_size());
    4130           0 :                         aWinSize.Width() = aPrefSize.Width() + nDiff;
    4131           0 :                         pWindow->SetSizePixel(aWinSize);
    4132             :                     }
    4133             : 
    4134             :                     //now reformat with final sizes
    4135           0 :                     mbFormat = true;
    4136           0 :                     ImplFormat(true);
    4137             :                 }
    4138             :             }
    4139             :         }
    4140             :     }
    4141             : 
    4142             :     // redraw border
    4143        8479 :     if ( mnWinStyle & WB_BORDER )
    4144             :     {
    4145             :         // as otherwise, when painting we might think we have to re-draw everything
    4146        4776 :         if ( mbFormat && IsReallyVisible() )
    4147           0 :             Invalidate();
    4148             :         else
    4149             :         {
    4150        4776 :             if ( mnRightBorder )
    4151             :             {
    4152         563 :                 if ( nOldDX > mnDX )
    4153           0 :                     Invalidate( Rectangle( mnDX-mnRightBorder-1, 0, mnDX, mnDY ) );
    4154             :                 else
    4155         563 :                     Invalidate( Rectangle( nOldDX-mnRightBorder-1, 0, nOldDX, nOldDY ) );
    4156             :             }
    4157             : 
    4158        4776 :             if ( mnBottomBorder )
    4159             :             {
    4160           0 :                 if ( nOldDY > mnDY )
    4161           0 :                     Invalidate( Rectangle( 0, mnDY-mnBottomBorder-1, mnDX, mnDY ) );
    4162             :                 else
    4163           0 :                     Invalidate( Rectangle( 0, nOldDY-mnBottomBorder-1, nOldDX, nOldDY ) );
    4164             :             }
    4165             :         }
    4166        8479 :     }
    4167             : }
    4168             : 
    4169           0 : const OUString& ToolBox::ImplGetHelpText( sal_uInt16 nItemId ) const
    4170             : {
    4171           0 :     ImplToolItem* pItem = ImplGetItem( nItemId );
    4172             : 
    4173             :     assert( pItem );
    4174             : 
    4175           0 :     if ( pItem->maHelpText.isEmpty() && ( !pItem->maHelpId.isEmpty() || pItem->maCommandStr.getLength() ))
    4176             :     {
    4177           0 :         Help* pHelp = Application::GetHelp();
    4178           0 :         if ( pHelp )
    4179             :         {
    4180           0 :             if ( pItem->maCommandStr.getLength() )
    4181           0 :                 pItem->maHelpText = pHelp->GetHelpText( pItem->maCommandStr, this );
    4182           0 :             if ( pItem->maHelpText.isEmpty() && !pItem->maHelpId.isEmpty() )
    4183           0 :                 pItem->maHelpText = pHelp->GetHelpText( OStringToOUString( pItem->maHelpId, RTL_TEXTENCODING_UTF8 ), this );
    4184             :         }
    4185             :     }
    4186             : 
    4187           0 :     return pItem->maHelpText;
    4188             : }
    4189             : 
    4190           0 : void ToolBox::RequestHelp( const HelpEvent& rHEvt )
    4191             : {
    4192             :     sal_uInt16 nItemId;
    4193           0 :     Point aHelpPos;
    4194             : 
    4195           0 :     if( !rHEvt.KeyboardActivated() )
    4196             :     {
    4197           0 :         nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) );
    4198           0 :         aHelpPos = rHEvt.GetMousePosPixel();
    4199             :     }
    4200             :     else
    4201             :     {
    4202           0 :         if( !mnHighItemId )
    4203           0 :             return;
    4204             :         else
    4205           0 :             nItemId = mnHighItemId;
    4206           0 :         Rectangle aRect( GetItemRect( nItemId ) );
    4207           0 :         if( aRect.IsEmpty() )
    4208           0 :             return;
    4209             :         else
    4210           0 :             aHelpPos = OutputToScreenPixel( aRect.Center() );
    4211             :     }
    4212             : 
    4213           0 :     if ( nItemId )
    4214             :     {
    4215           0 :         if ( rHEvt.GetMode() & (HELPMODE_BALLOON | HELPMODE_QUICK) )
    4216             :         {
    4217             :             // get rectangle
    4218           0 :             Rectangle aTempRect = GetItemRect( nItemId );
    4219           0 :             Point aPt = OutputToScreenPixel( aTempRect.TopLeft() );
    4220           0 :             aTempRect.Left()   = aPt.X();
    4221           0 :             aTempRect.Top()    = aPt.Y();
    4222           0 :             aPt = OutputToScreenPixel( aTempRect.BottomRight() );
    4223           0 :             aTempRect.Right()  = aPt.X();
    4224           0 :             aTempRect.Bottom() = aPt.Y();
    4225             : 
    4226             :             // get text and display it
    4227           0 :             OUString aStr = GetQuickHelpText( nItemId );
    4228           0 :             const OUString& rHelpStr = GetHelpText( nItemId );
    4229           0 :             if (aStr.isEmpty())
    4230           0 :                 aStr = MnemonicGenerator::EraseAllMnemonicChars( GetItemText( nItemId ) );
    4231           0 :             if ( rHEvt.GetMode() & HELPMODE_BALLOON )
    4232             :             {
    4233           0 :                 if (!rHelpStr.isEmpty())
    4234           0 :                     aStr = rHelpStr;
    4235           0 :                 Help::ShowBalloon( this, aHelpPos, aTempRect, aStr );
    4236             :             }
    4237             :             else
    4238           0 :                 Help::ShowQuickHelp( this, aTempRect, aStr, rHelpStr, QUICKHELP_CTRLTEXT );
    4239           0 :             return;
    4240             :         }
    4241           0 :         else if ( rHEvt.GetMode() & HELPMODE_EXTENDED )
    4242             :         {
    4243           0 :             OUString aCommand = GetItemCommand( nItemId );
    4244           0 :             OString  aHelpId( GetHelpId( nItemId ) );
    4245             : 
    4246           0 :             if ( !aCommand.isEmpty() || !aHelpId.isEmpty() )
    4247             :             {
    4248             :                 // If help is available then trigger it
    4249           0 :                 Help* pHelp = Application::GetHelp();
    4250           0 :                 if ( pHelp )
    4251             :                 {
    4252           0 :                     if ( !aCommand.isEmpty() )
    4253           0 :                         pHelp->Start( aCommand, this );
    4254           0 :                     else if ( !aHelpId.isEmpty() )
    4255           0 :                         pHelp->Start( OStringToOUString( aHelpId, RTL_TEXTENCODING_UTF8 ), this );
    4256             :                 }
    4257           0 :                 return;
    4258           0 :             }
    4259             :         }
    4260             :     }
    4261             : 
    4262           0 :     DockingWindow::RequestHelp( rHEvt );
    4263             : }
    4264             : 
    4265       14261 : bool ToolBox::Notify( NotifyEvent& rNEvt )
    4266             : {
    4267       14261 :     if ( rNEvt.GetType() == EVENT_KEYINPUT )
    4268             :     {
    4269           0 :         KeyEvent aKEvt = *rNEvt.GetKeyEvent();
    4270           0 :         KeyCode aKeyCode = aKEvt.GetKeyCode();
    4271           0 :         sal_uInt16  nKeyCode = aKeyCode.GetCode();
    4272           0 :         switch( nKeyCode )
    4273             :         {
    4274             :             case KEY_TAB:
    4275             :             {
    4276             :                 // internal TAB cycling only if parent is not a dialog or if we are the only child
    4277             :                 // otherwise the dialog control will take over
    4278           0 :                 Window *pParent = ImplGetParent();
    4279             :                 bool bOldSchoolContainer =
    4280           0 :                     ((pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL &&
    4281           0 :                     pParent->GetChildCount() != 1);
    4282           0 :                 bool bNoTabCycling = bOldSchoolContainer || isContainerWindow(pParent);
    4283             : 
    4284           0 :                 if( bNoTabCycling &&  ! (GetStyle() & WB_FORCETABCYCLE) )
    4285           0 :                     return DockingWindow::Notify( rNEvt );
    4286           0 :                 else if( ImplChangeHighlightUpDn( aKeyCode.IsShift() ? true : false , bNoTabCycling ) )
    4287           0 :                     return false;
    4288             :                 else
    4289           0 :                     return DockingWindow::Notify( rNEvt );
    4290             :             }
    4291             :             default:
    4292           0 :                 break;
    4293             :         };
    4294             :     }
    4295       14261 :     else if( rNEvt.GetType() == EVENT_GETFOCUS )
    4296             :     {
    4297           3 :         if( rNEvt.GetWindow() == this )
    4298             :         {
    4299             :             // the toolbar itself got the focus
    4300           1 :             if( mnLastFocusItemId != 0 )
    4301             :             {
    4302             :                 // restore last item
    4303           0 :                 ImplChangeHighlight( ImplGetItem( mnLastFocusItemId ) );
    4304           0 :                 mnLastFocusItemId = 0;
    4305             :             }
    4306           1 :             else if( (GetGetFocusFlags() & (GETFOCUS_BACKWARD|GETFOCUS_TAB) ) == (GETFOCUS_BACKWARD|GETFOCUS_TAB))
    4307             :                 // Shift-TAB was pressed in the parent
    4308           0 :                 ImplChangeHighlightUpDn( false );
    4309             :             else
    4310           1 :                 ImplChangeHighlightUpDn( true );
    4311             : 
    4312           1 :             mnLastFocusItemId = 0;
    4313             : 
    4314           1 :             return true;
    4315             :         }
    4316             :         else
    4317             :         {
    4318             :             // a child window got the focus so update current item to
    4319             :             // allow for proper lose focus handling in keyboard navigation
    4320           2 :             std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
    4321          46 :             while( it != mpData->m_aItems.end() )
    4322             :             {
    4323          43 :                 if ( it->mbVisible )
    4324             :                 {
    4325          31 :                     if ( it->mpWindow && it->mpWindow->ImplIsWindowOrChild( rNEvt.GetWindow() ) )
    4326             :                     {
    4327           1 :                         mnHighItemId = it->mnId;
    4328           1 :                         break;
    4329             :                     }
    4330             :                 }
    4331             : 
    4332          42 :                 ++it;
    4333             :             }
    4334           2 :             return DockingWindow::Notify( rNEvt );
    4335             :         }
    4336             :     }
    4337       14258 :     else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
    4338             :     {
    4339             :         // deselect
    4340           2 :         ImplHideFocus();
    4341           2 :         mnHighItemId = 0;
    4342           2 :         mnCurPos = TOOLBOX_ITEM_NOTFOUND;
    4343             :     }
    4344             : 
    4345       14258 :     return DockingWindow::Notify( rNEvt );
    4346             : }
    4347             : 
    4348           0 : void ToolBox::Command( const CommandEvent& rCEvt )
    4349             : {
    4350           0 :     if ( maCommandHandler.IsSet() )
    4351           0 :         maCommandHandler.Call( (void *)( &rCEvt ));
    4352             : 
    4353             :     // depict StartDrag on MouseButton/Left/Alt
    4354           0 :     if ( (rCEvt.GetCommand() == COMMAND_STARTDRAG) && rCEvt.IsMouseEvent() &&
    4355           0 :          mbCustomize && !mbDragging && !mbDrag && !mbSelection &&
    4356           0 :          (mnCurPos == TOOLBOX_ITEM_NOTFOUND) )
    4357             :     {
    4358             :         // We only allow dragging of items. Therefore, we have to check
    4359             :         // if an item was clicked, otherwise we could move the window, and
    4360             :         // this is unwanted.
    4361             :         // We only do this in customize mode, as otherwise
    4362             :         // items could be moved accidentally
    4363           0 :         if ( mbCustomizeMode )
    4364             :         {
    4365           0 :             Point           aMousePos = rCEvt.GetMousePosPixel();
    4366           0 :             std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
    4367           0 :             while ( it != mpData->m_aItems.end() )
    4368             :             {
    4369             :                 // is this the item?
    4370           0 :                 if ( it->maRect.IsInside( aMousePos ) )
    4371             :                 {
    4372             :                     // do nothing if it is a separator or
    4373             :                     // the item has been disabled
    4374           0 :                     if ( (it->meType == TOOLBOXITEM_BUTTON) &&
    4375           0 :                          !it->mbShowWindow )
    4376           0 :                         mbCommandDrag = true;
    4377           0 :                     break;
    4378             :                 }
    4379             : 
    4380           0 :                 ++it;
    4381             :             }
    4382             : 
    4383           0 :             if ( mbCommandDrag )
    4384             :             {
    4385             :                 MouseEvent aMEvt( aMousePos, 1, MOUSE_SIMPLECLICK,
    4386           0 :                                   MOUSE_LEFT, KEY_MOD2 );
    4387           0 :                 ToolBox::MouseButtonDown( aMEvt );
    4388           0 :                 return;
    4389             :             }
    4390             :         }
    4391             :     }
    4392           0 :     else if ( rCEvt.GetCommand() == COMMAND_WHEEL )
    4393             :     {
    4394           0 :         if ( (mnCurLine > 1) || (mnCurLine+mnVisLines-1 < mnCurLines) )
    4395             :         {
    4396           0 :             const CommandWheelData* pData = rCEvt.GetWheelData();
    4397           0 :             if ( pData->GetMode() == COMMAND_WHEEL_SCROLL )
    4398             :             {
    4399           0 :                 if ( (mnCurLine > 1) && (pData->GetDelta() > 0) )
    4400           0 :                     ShowLine( false );
    4401           0 :                 else if ( (mnCurLine+mnVisLines-1 < mnCurLines) && (pData->GetDelta() < 0) )
    4402           0 :                     ShowLine( true );
    4403           0 :                 ImplDrawSpin( false, false );
    4404           0 :                 return;
    4405             :             }
    4406             :         }
    4407             :     }
    4408             : 
    4409           0 :     DockingWindow::Command( rCEvt );
    4410             : }
    4411             : 
    4412       33852 : void ToolBox::StateChanged( StateChangedType nType )
    4413             : {
    4414       33852 :     DockingWindow::StateChanged( nType );
    4415             : 
    4416       33852 :     if ( nType == STATE_CHANGE_INITSHOW )
    4417        8865 :         ImplFormat();
    4418       24987 :     else if ( nType == STATE_CHANGE_ENABLE )
    4419        3029 :         ImplUpdateItem();
    4420       21958 :     else if ( nType == STATE_CHANGE_UPDATEMODE )
    4421             :     {
    4422           0 :         if ( IsUpdateMode() )
    4423           0 :             Invalidate();
    4424             :     }
    4425       43916 :     else if ( (nType == STATE_CHANGE_ZOOM) ||
    4426       21958 :               (nType == STATE_CHANGE_CONTROLFONT) )
    4427             :     {
    4428           0 :         mbCalc = true;
    4429           0 :         mbFormat = true;
    4430           0 :         ImplInitSettings( true, false, false );
    4431           0 :         Invalidate();
    4432             :     }
    4433       21958 :     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
    4434             :     {
    4435           0 :         ImplInitSettings( false, true, false );
    4436           0 :         Invalidate();
    4437             :     }
    4438       21958 :     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
    4439             :     {
    4440           0 :         ImplInitSettings( false, false, true ); // font, foreground, background
    4441           0 :         Invalidate();
    4442             :     }
    4443             : 
    4444       33852 :     if ( maStateChangedHandler.IsSet() )
    4445       21468 :         maStateChangedHandler.Call( &nType );
    4446       33852 : }
    4447             : 
    4448         208 : void ToolBox::DataChanged( const DataChangedEvent& rDCEvt )
    4449             : {
    4450         208 :     DockingWindow::DataChanged( rDCEvt );
    4451             : 
    4452         624 :     if ( (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
    4453         416 :          (rDCEvt.GetType() == DATACHANGED_FONTS) ||
    4454         782 :          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
    4455         416 :          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
    4456         208 :           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
    4457             :     {
    4458         158 :         mbCalc = true;
    4459         158 :         mbFormat = true;
    4460         158 :         ImplInitSettings( true, true, true );
    4461         158 :         Invalidate();
    4462             :     }
    4463             : 
    4464         208 :     if ( maDataChangedHandler.IsSet() )
    4465           6 :         maDataChangedHandler.Call( (void*)&rDCEvt );
    4466         208 : }
    4467             : 
    4468           0 : bool ToolBox::PrepareToggleFloatingMode()
    4469             : {
    4470           0 :     return DockingWindow::PrepareToggleFloatingMode();
    4471             : }
    4472             : 
    4473           0 : void ToolBox::ToggleFloatingMode()
    4474             : {
    4475           0 :     DockingWindow::ToggleFloatingMode();
    4476             : 
    4477           0 :     bool mbOldHorz = mbHorz;
    4478             : 
    4479           0 :     if ( ImplIsFloatingMode() )
    4480             :     {
    4481           0 :         mbHorz   = true;
    4482           0 :         meAlign  = WINDOWALIGN_TOP;
    4483           0 :         mbScroll = true;
    4484             : 
    4485           0 :         if( mbOldHorz != mbHorz )
    4486           0 :             mbCalc = true;  // orientation was changed !
    4487             : 
    4488           0 :         ImplSetMinMaxFloatSize( this );
    4489           0 :         SetOutputSizePixel( ImplCalcFloatSize( this, mnFloatLines ) );
    4490             :     }
    4491             :     else
    4492             :     {
    4493           0 :         mbScroll = (mnWinStyle & WB_SCROLL) ? true : false;
    4494           0 :         if ( (meAlign == WINDOWALIGN_TOP) || (meAlign == WINDOWALIGN_BOTTOM) )
    4495           0 :             mbHorz = true;
    4496             :         else
    4497           0 :             mbHorz = false;
    4498             : 
    4499             :         // set focus back to document
    4500           0 :         ImplGetFrameWindow()->GetWindow( WINDOW_CLIENT )->GrabFocus();
    4501             :     }
    4502             : 
    4503           0 :     if( mbOldHorz != mbHorz )
    4504             :     {
    4505             :         // if orientation changes, the toolbox has to be initialized again
    4506             :         // to update the direction of the gradient
    4507           0 :         mbCalc = true;
    4508           0 :         ImplInitSettings( true, true, true );
    4509             :     }
    4510             : 
    4511           0 :     mbFormat = true;
    4512           0 :     ImplFormat();
    4513           0 : }
    4514             : 
    4515           0 : void ToolBox::StartDocking()
    4516             : {
    4517           0 :     meDockAlign = meAlign;
    4518           0 :     mnDockLines = mnLines;
    4519           0 :     mbLastFloatMode = ImplIsFloatingMode();
    4520           0 :     DockingWindow::StartDocking();
    4521           0 : }
    4522             : 
    4523           0 : bool ToolBox::Docking( const Point& rPos, Rectangle& rRect )
    4524             : {
    4525             :     // do nothing during dragging, it was calculated before
    4526           0 :     if ( mbDragging )
    4527           0 :         return false;
    4528             : 
    4529           0 :     bool bFloatMode = false;
    4530             : 
    4531           0 :     DockingWindow::Docking( rPos, rRect );
    4532             : 
    4533             :     // if the mouse is outside the area, it can only become a floating window
    4534           0 :     Rectangle aDockingRect( rRect );
    4535           0 :     if ( !ImplIsFloatingMode() )
    4536             :     {
    4537             :         // don't use tracking rectangle for alignment check, because it will be too large
    4538             :         // to get a floating mode as result - switch to floating size
    4539             :         // so the calculation only depends on the position of the rectangle, not the current
    4540             :         // docking state of the window
    4541           0 :         sal_uInt16 nTemp = 0;
    4542           0 :         aDockingRect.SetSize( ImplCalcFloatSize( this, nTemp ) );
    4543             : 
    4544             :         // in this mode docking is never done by keyboard, so it's OK to use the mouse position
    4545           0 :         aDockingRect.SetPos( ImplGetFrameWindow()->GetPointerPosPixel() );
    4546             :     }
    4547             : 
    4548           0 :     Rectangle aIntersection = maOutDockRect.GetIntersection( aDockingRect );
    4549           0 :     if ( !aIntersection.IsEmpty() && !IsDockingPrevented() )
    4550             :     {
    4551           0 :         Rectangle   aInRect = maInDockRect;
    4552           0 :         Size aDockSize;
    4553           0 :         aDockSize.Width()  = ImplCalcSize( this, mnLines, TB_CALCMODE_VERT ).Width();
    4554           0 :         aDockSize.Height() = ImplCalcSize( this, mnLines, TB_CALCMODE_HORZ ).Height();
    4555           0 :         aInRect.Left()   += aDockSize.Width()/2;
    4556           0 :         aInRect.Top()    += aDockSize.Height()/2;
    4557           0 :         aInRect.Right()  -= aDockSize.Width()/2;
    4558           0 :         aInRect.Bottom() -= aDockSize.Height()/2;
    4559             : 
    4560             :         // if the window is too small, use the complete InDock-Rect
    4561           0 :         if ( aInRect.Left() >= aInRect.Right() )
    4562             :         {
    4563           0 :             aInRect.Left()  = maInDockRect.Left();
    4564           0 :             aInRect.Right() = maInDockRect.Right();
    4565             :         }
    4566           0 :         if ( aInRect.Top() >= aInRect.Bottom() )
    4567             :         {
    4568           0 :             aInRect.Top()    = maInDockRect.Top();
    4569           0 :             aInRect.Bottom() = maInDockRect.Bottom();
    4570             :         }
    4571             : 
    4572             :         // if the mouse is outside the Dock area, it can only
    4573             :         // become a floating window
    4574           0 :         Rectangle aIntersect = aInRect.GetIntersection( aDockingRect );
    4575           0 :         if ( aIntersect == aDockingRect )
    4576           0 :             bFloatMode = true;
    4577             :         else
    4578             :         {
    4579             :             // docking rectangle is in the "sensible area"
    4580           0 :             Point aPos = aDockingRect.TopLeft();
    4581           0 :             Point aInPosTL( aPos.X()-aInRect.Left(), aPos.Y()-aInRect.Top() );
    4582           0 :             Point aInPosBR( aPos.X()-aInRect.Left() + aDockingRect.GetWidth(), aPos.Y()-aInRect.Top() + aDockingRect.GetHeight() );
    4583           0 :             Size  aInSize = aInRect.GetSize();
    4584             : 
    4585           0 :             if ( aInPosTL.X() <= 0 )
    4586           0 :                 meDockAlign = WINDOWALIGN_LEFT;
    4587           0 :             else if ( aInPosTL.Y() <= 0)
    4588           0 :                 meDockAlign = WINDOWALIGN_TOP;
    4589           0 :             else if ( aInPosBR.X() >= aInSize.Width() )
    4590           0 :                 meDockAlign = WINDOWALIGN_RIGHT;
    4591           0 :             else if ( aInPosBR.Y() >= aInSize.Height() )
    4592           0 :                 meDockAlign = WINDOWALIGN_BOTTOM;
    4593             : 
    4594             :             // update the Dock size if Dock-Align was changed
    4595           0 :             if ( (meDockAlign == WINDOWALIGN_TOP) || (meDockAlign == WINDOWALIGN_BOTTOM) )
    4596           0 :                 aDockSize.Width() = maInDockRect.GetWidth();
    4597             :             else
    4598           0 :                 aDockSize.Height() = maInDockRect.GetHeight();
    4599             : 
    4600           0 :             aDockingRect.SetSize( aDockSize );
    4601             : 
    4602           0 :             Point aPosTL( maInDockRect.TopLeft() );
    4603           0 :             switch ( meDockAlign )
    4604             :             {
    4605             :                 case WINDOWALIGN_TOP :
    4606           0 :                     aDockingRect.SetPos( aPosTL );
    4607           0 :                     break;
    4608             :                 case WINDOWALIGN_LEFT :
    4609           0 :                     aDockingRect.SetPos( aPosTL );
    4610           0 :                     break;
    4611             :                 case WINDOWALIGN_BOTTOM :
    4612             :                 {
    4613           0 :                     Point aPosBL( maInDockRect.BottomLeft() );
    4614           0 :                     aPosBL.Y() -= aDockingRect.GetHeight();
    4615           0 :                     aDockingRect.SetPos( aPosBL );
    4616           0 :                     break;
    4617             :                 }
    4618             :                 case WINDOWALIGN_RIGHT :
    4619             :                 {
    4620           0 :                     Point aPosTR( maInDockRect.TopRight() );
    4621           0 :                     aPosTR.X() -= aDockingRect.GetWidth();
    4622           0 :                     aDockingRect.SetPos( aPosTR );
    4623           0 :                     break;
    4624             :                 }
    4625             :             }
    4626             :         }
    4627             :     }
    4628             :     else
    4629           0 :         bFloatMode = true;
    4630             : 
    4631           0 :     if ( bFloatMode )
    4632             :     {
    4633           0 :         meDockAlign = meAlign;
    4634           0 :         if ( !mbLastFloatMode )
    4635             :         {
    4636           0 :             sal_uInt16 nTemp = 0;
    4637           0 :             aDockingRect.SetSize( ImplCalcFloatSize( this, nTemp ) );
    4638             :         }
    4639             :     }
    4640             : 
    4641           0 :     rRect = aDockingRect;
    4642           0 :     mbLastFloatMode = bFloatMode;
    4643             : 
    4644           0 :     return bFloatMode;
    4645             : }
    4646             : 
    4647           0 : void ToolBox::EndDocking( const Rectangle& rRect, bool bFloatMode )
    4648             : {
    4649           0 :     if ( !IsDockingCanceled() )
    4650             :     {
    4651           0 :         if ( mnLines != mnDockLines )
    4652           0 :             SetLineCount( mnDockLines );
    4653           0 :         if ( meAlign != meDockAlign )
    4654           0 :             SetAlign( meDockAlign );
    4655             :     }
    4656           0 :     if ( bFloatMode || (bool(bFloatMode) != ImplIsFloatingMode()) )
    4657           0 :         DockingWindow::EndDocking( rRect, bFloatMode );
    4658           0 : }
    4659             : 
    4660           0 : void ToolBox::Resizing( Size& rSize )
    4661             : {
    4662             :     sal_uInt16  nCalcLines;
    4663             :     sal_uInt16  nTemp;
    4664             : 
    4665             :     // Alle Floatinggroessen berechnen
    4666           0 :     ImplCalcFloatSizes( this );
    4667             : 
    4668           0 :     if ( !mnLastResizeDY )
    4669           0 :         mnLastResizeDY = mnDY;
    4670             : 
    4671             :     // Ist vertikales Resizing angesagt
    4672           0 :     if ( (mnLastResizeDY != rSize.Height()) && (mnDY != rSize.Height()) )
    4673             :     {
    4674           0 :         nCalcLines = ImplCalcLines( this, rSize.Height() );
    4675           0 :         if ( nCalcLines < 1 )
    4676           0 :             nCalcLines = 1;
    4677           0 :         rSize = ImplCalcFloatSize( this, nCalcLines );
    4678             :     }
    4679             :     else
    4680             :     {
    4681           0 :         nCalcLines = 1;
    4682           0 :         nTemp = nCalcLines;
    4683           0 :         Size aTempSize = ImplCalcFloatSize( this, nTemp );
    4684           0 :         while ( (aTempSize.Width() > rSize.Width()) &&
    4685           0 :                 (nCalcLines <= maFloatSizes[0].mnLines) )
    4686             :         {
    4687           0 :             nCalcLines++;
    4688           0 :             nTemp = nCalcLines;
    4689           0 :             aTempSize = ImplCalcFloatSize( this, nTemp );
    4690             :         }
    4691           0 :         rSize = aTempSize;
    4692             :     }
    4693             : 
    4694           0 :     mnLastResizeDY = rSize.Height();
    4695           0 : }
    4696             : 
    4697           0 : Size ToolBox::GetOptimalSize() const
    4698             : {
    4699             :     // If we have any expandable entries, then force them to their
    4700             :     // optimal sizes, then reset them afterwards
    4701           0 :     std::map<Window*, Size> aExpandables;
    4702           0 :     for (size_t i = 0; i < mpData->m_aItems.size(); ++i)
    4703             :     {
    4704           0 :         if (mpData->m_aItems[i].mbExpand)
    4705             :         {
    4706           0 :             Window *pWindow = mpData->m_aItems[i].mpWindow;
    4707             :             SAL_WARN_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment");
    4708           0 :             if (!pWindow)
    4709           0 :                 continue;
    4710           0 :             Size aWinSize(pWindow->GetSizePixel());
    4711           0 :             aExpandables[pWindow] = aWinSize;
    4712           0 :             Size aPrefSize(pWindow->get_preferred_size());
    4713           0 :             aWinSize.Width() = aPrefSize.Width();
    4714           0 :             pWindow->SetSizePixel(aWinSize);
    4715             :         }
    4716             :     }
    4717             : 
    4718           0 :     Size aSize(ImplCalcSize( this, mnLines ));
    4719             : 
    4720           0 :     for (std::map<Window*, Size>::iterator aI = aExpandables.begin(); aI != aExpandables.end(); ++aI)
    4721             :     {
    4722           0 :         Window *pWindow = aI->first;
    4723           0 :         Size aWinSize = aI->second;
    4724           0 :         pWindow->SetSizePixel(aWinSize);
    4725             :     }
    4726             : 
    4727           0 :     return aSize;
    4728             : }
    4729             : 
    4730       26801 : Size ToolBox::CalcWindowSizePixel( sal_uInt16 nCalcLines ) const
    4731             : {
    4732       26801 :     return ImplCalcSize( this, nCalcLines );
    4733             : }
    4734             : 
    4735           0 : Size ToolBox::CalcWindowSizePixel( sal_uInt16 nCalcLines, WindowAlign eAlign ) const
    4736             : {
    4737             :     return ImplCalcSize( this, nCalcLines,
    4738           0 :         (eAlign == WINDOWALIGN_TOP || eAlign == WINDOWALIGN_BOTTOM) ? TB_CALCMODE_HORZ : TB_CALCMODE_VERT );
    4739             : }
    4740             : 
    4741           0 : sal_uInt16 ToolBox::ImplCountLineBreaks( const ToolBox *pThis )
    4742             : {
    4743           0 :     sal_uInt16 nLines = 0;
    4744             : 
    4745           0 :     std::vector< ImplToolItem >::const_iterator it = ((ToolBox*)pThis)->mpData->m_aItems.begin();
    4746           0 :     while ( it != ((ToolBox*)pThis)->mpData->m_aItems.end() )
    4747             :     {
    4748           0 :         if( it->meType == TOOLBOXITEM_BREAK )
    4749           0 :             ++nLines;
    4750           0 :         ++it;
    4751             :     }
    4752           0 :     return nLines;
    4753             : }
    4754             : 
    4755           0 : Size ToolBox::CalcPopupWindowSizePixel() const
    4756             : {
    4757             :     // count number of breaks and calc corresponding floating window size
    4758           0 :     sal_uInt16 nLines = ImplCountLineBreaks( this );
    4759             : 
    4760           0 :     if( nLines )
    4761           0 :         ++nLines;   // add the first line
    4762             :     else
    4763             :     {
    4764             :         // no breaks found: use quadratic layout
    4765           0 :         nLines = (sal_uInt16) ceil( sqrt( (double) GetItemCount() ) );
    4766             :     }
    4767             : 
    4768           0 :     bool bPopup = mpData->mbAssumePopupMode;
    4769           0 :     ToolBox *pThis = (ToolBox*) this;
    4770           0 :     pThis->mpData->mbAssumePopupMode = true;
    4771             : 
    4772           0 :     Size aSize = CalcFloatingWindowSizePixel( nLines );
    4773             : 
    4774           0 :     pThis->mpData->mbAssumePopupMode = bPopup;
    4775           0 :     return aSize;
    4776             : }
    4777             : 
    4778           0 : Size ToolBox::CalcFloatingWindowSizePixel() const
    4779             : {
    4780           0 :     sal_uInt16 nLines = ImplCountLineBreaks( this );
    4781           0 :     ++nLines; // add the first line
    4782           0 :     return CalcFloatingWindowSizePixel( nLines );
    4783             : }
    4784             : 
    4785           0 : Size ToolBox::CalcFloatingWindowSizePixel( sal_uInt16 nCalcLines ) const
    4786             : {
    4787           0 :     bool bFloat = mpData->mbAssumeFloating;
    4788           0 :     bool bDocking = mpData->mbAssumeDocked;
    4789             : 
    4790             :     // simulate floating mode and force reformat before calculating
    4791           0 :     ToolBox *pThis = (ToolBox*) this;
    4792           0 :     pThis->mpData->mbAssumeFloating = true;
    4793           0 :     pThis->mpData->mbAssumeDocked = false;
    4794             : 
    4795           0 :     Size aSize = ImplCalcFloatSize( (ToolBox*) this, nCalcLines );
    4796             : 
    4797           0 :     pThis->mbFormat = true;
    4798           0 :     pThis->mpData->mbAssumeFloating = bFloat;
    4799           0 :     pThis->mpData->mbAssumeDocked = bDocking;
    4800             : 
    4801           0 :     return aSize;
    4802             : }
    4803             : 
    4804         357 : Size ToolBox::CalcMinimumWindowSizePixel() const
    4805             : {
    4806         357 :     if( ImplIsFloatingMode() )
    4807           0 :         return ImplCalcSize( this, mnFloatLines );
    4808             :     else
    4809             :     {
    4810             :         // create dummy toolbox for measurements
    4811         357 :         ToolBox *pToolBox = new ToolBox( GetParent(), GetStyle() );
    4812             : 
    4813             :         // copy until first useful item
    4814         357 :         std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
    4815         357 :         while( it != mpData->m_aItems.end() )
    4816             :         {
    4817         357 :             pToolBox->CopyItem( *this, it->mnId );
    4818        1071 :             if( (it->meType != TOOLBOXITEM_BUTTON) ||
    4819         714 :                 !it->mbVisible || ImplIsFixedControl( &(*it) ) )
    4820           0 :                 ++it;
    4821             :             else
    4822         357 :                 break;
    4823             :         }
    4824             : 
    4825             :         // add to docking manager if required to obtain a drag area
    4826             :         // (which is accounted for in calcwindowsizepixel)
    4827         357 :         if( ImplGetDockingManager()->GetDockingWindowWrapper( this ) )
    4828         357 :             ImplGetDockingManager()->AddWindow( pToolBox );
    4829             : 
    4830             :         // account for menu
    4831         357 :         if( IsMenuEnabled() )
    4832         357 :             pToolBox->SetMenuType( GetMenuType() );
    4833             : 
    4834         357 :         pToolBox->SetAlign( GetAlign() );
    4835         357 :         Size aSize = pToolBox->CalcWindowSizePixel( 1 );
    4836             : 
    4837         357 :         ImplGetDockingManager()->RemoveWindow( pToolBox );
    4838         357 :         pToolBox->Clear();
    4839         357 :         delete pToolBox;
    4840             : 
    4841         357 :         return aSize;
    4842             :     }
    4843             : }
    4844             : 
    4845        6103 : void ToolBox::EnableCustomize( bool bEnable )
    4846             : {
    4847        6103 :     if ( bEnable != mbCustomize )
    4848             :     {
    4849        6103 :         mbCustomize = bEnable;
    4850             : 
    4851        6103 :         ImplTBDragMgr* pMgr = ImplGetTBDragMgr();
    4852        6103 :         if ( bEnable )
    4853        6103 :             pMgr->push_back( this );
    4854             :         else
    4855           0 :             pMgr->erase( this );
    4856             :     }
    4857        6103 : }
    4858             : 
    4859           1 : void ToolBox::GetFocus()
    4860             : {
    4861           1 :     DockingWindow::GetFocus();
    4862           1 : }
    4863             : 
    4864           0 : void ToolBox::LoseFocus()
    4865             : {
    4866           0 :     ImplChangeHighlight( NULL, true );
    4867             : 
    4868           0 :     DockingWindow::LoseFocus();
    4869           0 : }
    4870             : 
    4871             : // performs the action associated with an item, ie simulates clicking the item
    4872           2 : void ToolBox::TriggerItem( sal_uInt16 nItemId, bool bShift, bool bCtrl )
    4873             : {
    4874           2 :     mnHighItemId = nItemId;
    4875           2 :     sal_uInt16 nModifier = 0;
    4876           2 :     if( bShift )
    4877           0 :         nModifier |= KEY_SHIFT;
    4878           2 :     if( bCtrl )
    4879           0 :         nModifier |= KEY_MOD1;
    4880           2 :     KeyCode aKeyCode( 0, nModifier );
    4881           2 :     ImplActivateItem( aKeyCode );
    4882           2 : }
    4883             : 
    4884             : // calls the button's action handler
    4885             : // returns true if action was called
    4886           2 : bool ToolBox::ImplActivateItem( KeyCode aKeyCode )
    4887             : {
    4888           2 :     bool bRet = true;
    4889           2 :     if( mnHighItemId )
    4890             :     {
    4891           2 :         ImplToolItem *pToolItem = ImplGetItem( mnHighItemId );
    4892             : 
    4893             :         // #107712#, activate can also be called for disabled entries
    4894           2 :         if( pToolItem && !pToolItem->mbEnabled )
    4895           0 :             return true;
    4896             : 
    4897           2 :         if( pToolItem && pToolItem->mpWindow && HasFocus() )
    4898             :         {
    4899           0 :             ImplHideFocus();
    4900           0 :             mbChangingHighlight = true;  // avoid focus change due to loose focus
    4901           0 :             pToolItem->mpWindow->ImplControlFocus( GETFOCUS_TAB );
    4902           0 :             mbChangingHighlight = false;
    4903             :         }
    4904             :         else
    4905             :         {
    4906           2 :             mnDownItemId = mnCurItemId = mnHighItemId;
    4907           2 :             ImplToolItem* pItem = ImplGetItem( mnHighItemId );
    4908           2 :             if ( pItem->mnBits & TIB_AUTOCHECK )
    4909             :             {
    4910           0 :                 if ( pItem->mnBits & TIB_RADIOCHECK )
    4911             :                 {
    4912           0 :                     if ( pItem->meState != TRISTATE_TRUE )
    4913           0 :                         SetItemState( pItem->mnId, TRISTATE_TRUE );
    4914             :                 }
    4915             :                 else
    4916             :                 {
    4917           0 :                     if ( pItem->meState != TRISTATE_TRUE )
    4918           0 :                         pItem->meState = TRISTATE_TRUE;
    4919             :                     else
    4920           0 :                         pItem->meState = TRISTATE_FALSE;
    4921             :                 }
    4922             :             }
    4923           2 :             mnMouseModifier = aKeyCode.GetModifier();
    4924           2 :             mbIsKeyEvent = true;
    4925           2 :             Activate();
    4926           2 :             Click();
    4927             : 
    4928             :             // #107776# we might be destroyed in the selecthandler
    4929           2 :             ImplDelData aDelData;
    4930           2 :             ImplAddDel( &aDelData );
    4931           2 :             Select();
    4932           2 :             if ( aDelData.IsDead() )
    4933           0 :                 return bRet;
    4934           2 :             ImplRemoveDel( &aDelData );
    4935             : 
    4936           2 :             Deactivate();
    4937           2 :             mbIsKeyEvent = false;
    4938           2 :             mnMouseModifier = 0;
    4939             :         }
    4940             :     }
    4941             :     else
    4942           0 :         bRet = false;
    4943           2 :     return bRet;
    4944             : }
    4945             : 
    4946           0 : bool ImplCloseLastPopup( Window *pParent )
    4947             : {
    4948             :     // close last popup toolbox (see also:
    4949             :     // ImplHandleMouseFloatMode(...) in winproc.cxx )
    4950             : 
    4951           0 :     if( ImplGetSVData()->maWinData.mpFirstFloat )
    4952             :     {
    4953           0 :         FloatingWindow* pLastLevelFloat = ImplGetSVData()->maWinData.mpFirstFloat->ImplFindLastLevelFloat();
    4954             :         // only close the floater if it is not our direct parent, which would kill ourself
    4955           0 :         if( pLastLevelFloat && pLastLevelFloat != pParent )
    4956             :         {
    4957           0 :             pLastLevelFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
    4958           0 :             return true;
    4959             :         }
    4960             :     }
    4961           0 :     return false;
    4962             : }
    4963             : 
    4964             : // opens a drop down toolbox item
    4965             : // returns true if item was opened
    4966           0 : bool ToolBox::ImplOpenItem( KeyCode aKeyCode )
    4967             : {
    4968           0 :     sal_uInt16 nCode = aKeyCode.GetCode();
    4969           0 :     bool bRet = true;
    4970             : 
    4971             :     // arrow keys should work only in the opposite direction of alignment (to not break cursor travelling)
    4972           0 :     if ( ((nCode == KEY_LEFT || nCode == KEY_RIGHT) && IsHorizontal())
    4973           0 :       || ((nCode == KEY_UP   || nCode == KEY_DOWN)  && !IsHorizontal()) )
    4974           0 :         return false;
    4975             : 
    4976           0 :     if( IsMenuEnabled() && mpData->mbMenubuttonSelected )
    4977             :     {
    4978           0 :         if( ImplCloseLastPopup( GetParent() ) )
    4979           0 :             return bRet;
    4980             : 
    4981           0 :         UpdateCustomMenu();
    4982           0 :         Application::PostUserEvent( mpData->mnEventId, LINK( this, ToolBox, ImplCallExecuteCustomMenu ) );
    4983             :     }
    4984           0 :     else if( mnHighItemId &&  ImplGetItem( mnHighItemId ) &&
    4985           0 :         (ImplGetItem( mnHighItemId )->mnBits & TIB_DROPDOWN) )
    4986             :     {
    4987           0 :         if( ImplCloseLastPopup( GetParent() ) )
    4988           0 :             return bRet;
    4989             : 
    4990           0 :         mnDownItemId = mnCurItemId = mnHighItemId;
    4991           0 :         mnCurPos = GetItemPos( mnCurItemId );
    4992           0 :         mnLastFocusItemId = mnCurItemId; // save item id for possible later focus restore
    4993           0 :         mnMouseModifier = aKeyCode.GetModifier();
    4994           0 :         mbIsShift = true;
    4995           0 :         mbIsKeyEvent = true;
    4996           0 :         Activate();
    4997             : 
    4998           0 :         mpData->mbDropDownByKeyboard = true;
    4999           0 :         GetDropdownClickHdl().Call( this );
    5000             : 
    5001           0 :         mbIsKeyEvent = false;
    5002           0 :         mbIsShift = false;
    5003           0 :         mnMouseModifier = 0;
    5004             :     }
    5005             :     else
    5006           0 :         bRet = false;
    5007             : 
    5008           0 :     return bRet;
    5009             : }
    5010             : 
    5011           0 : void ToolBox::KeyInput( const KeyEvent& rKEvt )
    5012             : {
    5013           0 :     KeyCode aKeyCode = rKEvt.GetKeyCode();
    5014           0 :     mnKeyModifier = aKeyCode.GetModifier();
    5015           0 :     sal_uInt16 nCode = aKeyCode.GetCode();
    5016             : 
    5017           0 :     Window *pParent = ImplGetParent();
    5018           0 :     bool bOldSchoolContainer = ((pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL);
    5019           0 :     bool bParentIsContainer = bOldSchoolContainer || isContainerWindow(pParent);
    5020             : 
    5021           0 :     bool bForwardKey = false;
    5022           0 :     bool bGrabFocusToDocument = false;
    5023             : 
    5024             :     // #107776# we might be destroyed in the keyhandler
    5025           0 :     ImplDelData aDelData;
    5026           0 :     ImplAddDel( &aDelData );
    5027             : 
    5028           0 :     switch ( nCode )
    5029             :     {
    5030             :         case KEY_UP:
    5031             :         {
    5032             :             // Ctrl-Cursor activates next toolbox, indicated by a blue arrow pointing to the left/up
    5033           0 :             if( aKeyCode.GetModifier() )    // allow only pure cursor keys
    5034           0 :                 break;
    5035           0 :             if( !IsHorizontal() )
    5036           0 :                 ImplChangeHighlightUpDn( true );
    5037             :             else
    5038           0 :                 ImplOpenItem( aKeyCode );
    5039             :         }
    5040           0 :         break;
    5041             :         case KEY_LEFT:
    5042             :         {
    5043           0 :             if( aKeyCode.GetModifier() )    // allow only pure cursor keys
    5044           0 :                 break;
    5045           0 :             if( IsHorizontal() )
    5046           0 :                 ImplChangeHighlightUpDn( true );
    5047             :             else
    5048           0 :                 ImplOpenItem( aKeyCode );
    5049             :         }
    5050           0 :         break;
    5051             :         case KEY_DOWN:
    5052             :         {
    5053           0 :             if( aKeyCode.GetModifier() )    // allow only pure cursor keys
    5054           0 :                 break;
    5055           0 :             if( !IsHorizontal() )
    5056           0 :                 ImplChangeHighlightUpDn( false );
    5057             :             else
    5058           0 :                 ImplOpenItem( aKeyCode );
    5059             :         }
    5060           0 :         break;
    5061             :         case KEY_RIGHT:
    5062             :         {
    5063           0 :             if( aKeyCode.GetModifier() )    // allow only pure cursor keys
    5064           0 :                 break;
    5065           0 :             if( IsHorizontal() )
    5066           0 :                 ImplChangeHighlightUpDn( false );
    5067             :             else
    5068           0 :                 ImplOpenItem( aKeyCode );
    5069             :         }
    5070           0 :         break;
    5071             :         case KEY_PAGEUP:
    5072           0 :             if ( mnCurLine > 1 )
    5073             :             {
    5074           0 :                 if( mnCurLine > mnVisLines )
    5075           0 :                     mnCurLine = mnCurLine - mnVisLines;
    5076             :                 else
    5077           0 :                     mnCurLine = 1;
    5078           0 :                 mbFormat = true;
    5079           0 :                 ImplFormat();
    5080           0 :                 ImplDrawSpin( false, false );
    5081           0 :                 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine ) );
    5082             :             }
    5083           0 :         break;
    5084             :         case KEY_PAGEDOWN:
    5085           0 :             if ( mnCurLine+mnVisLines-1 < mnCurLines )
    5086             :             {
    5087           0 :                 if( mnCurLine + 2*mnVisLines-1 < mnCurLines )
    5088           0 :                     mnCurLine = mnCurLine + mnVisLines;
    5089             :                 else
    5090           0 :                     mnCurLine = mnCurLines;
    5091           0 :                 mbFormat = true;
    5092           0 :                 ImplFormat();
    5093           0 :                 ImplDrawSpin( false, false );
    5094           0 :                 ImplChangeHighlight( ImplGetFirstValidItem( mnCurLine ) );
    5095             :             }
    5096           0 :         break;
    5097             :         case KEY_END:
    5098             :             {
    5099           0 :                 ImplChangeHighlight( NULL );
    5100           0 :                 ImplChangeHighlightUpDn( false );
    5101             :             }
    5102           0 :             break;
    5103             :         case KEY_HOME:
    5104             :             {
    5105           0 :                 ImplChangeHighlight( NULL );
    5106           0 :                 ImplChangeHighlightUpDn( true );
    5107             :             }
    5108           0 :             break;
    5109             :         case KEY_ESCAPE:
    5110             :         {
    5111           0 :             if( !ImplIsFloatingMode() && bParentIsContainer )
    5112           0 :                 DockingWindow::KeyInput( rKEvt );
    5113             :             else
    5114             :             {
    5115             :                 // send focus to document pane
    5116           0 :                 Window *pWin = this;
    5117           0 :                 while( pWin )
    5118             :                 {
    5119           0 :                     if( !pWin->GetParent() )
    5120             :                     {
    5121           0 :                         pWin->ImplGetFrameWindow()->GetWindow( WINDOW_CLIENT )->GrabFocus();
    5122           0 :                         break;
    5123             :                     }
    5124           0 :                     pWin = pWin->GetParent();
    5125             :                 }
    5126             :             }
    5127             :         }
    5128           0 :         break;
    5129             :         case KEY_RETURN:
    5130             :         {
    5131             :             // #107712#, disabled entries are selectable now
    5132             :             //  leave toolbox and move focus to document
    5133           0 :             if( mnHighItemId )
    5134             :             {
    5135           0 :                 ImplToolItem *pItem = ImplGetItem( mnHighItemId );
    5136           0 :                 if( !pItem->mbEnabled )
    5137             :                 {
    5138           0 :                     bGrabFocusToDocument = true;
    5139             :                 }
    5140             :             }
    5141           0 :             if( !bGrabFocusToDocument )
    5142           0 :                 bForwardKey = !ImplActivateItem( aKeyCode );
    5143             :         }
    5144           0 :         break;
    5145             :         default:
    5146             :             {
    5147           0 :             sal_uInt16 aKeyGroup = aKeyCode.GetGroup();
    5148           0 :             ImplToolItem *pItem = NULL;
    5149           0 :             if( mnHighItemId )
    5150           0 :                 pItem = ImplGetItem( mnHighItemId );
    5151             :             // #i13931# forward alphanum keyinput into embedded control
    5152           0 :             if( (aKeyGroup == KEYGROUP_NUM || aKeyGroup == KEYGROUP_ALPHA ) && pItem && pItem->mpWindow && pItem->mbEnabled )
    5153             :             {
    5154           0 :                 Window *pFocusWindow = Application::GetFocusWindow();
    5155           0 :                 ImplHideFocus();
    5156           0 :                 mbChangingHighlight = true;  // avoid focus change due to loose focus
    5157           0 :                 pItem->mpWindow->ImplControlFocus( GETFOCUS_TAB );
    5158           0 :                 mbChangingHighlight = false;
    5159           0 :                 if( pFocusWindow != Application::GetFocusWindow() )
    5160           0 :                     Application::GetFocusWindow()->KeyInput( rKEvt );
    5161             :             }
    5162             :             else
    5163             :             {
    5164             :                 // do nothing to avoid key presses going into the document
    5165             :                 // while the toolbox has the focus
    5166             :                 // just forward function and special keys and combinations with Alt-key
    5167           0 :                 if( aKeyGroup == KEYGROUP_FKEYS || aKeyGroup == KEYGROUP_MISC || aKeyCode.IsMod2() )
    5168           0 :                     bForwardKey = true;
    5169             :             }
    5170             :         }
    5171             :     }
    5172             : 
    5173           0 :     if ( aDelData.IsDead() )
    5174           0 :         return;
    5175           0 :     ImplRemoveDel( &aDelData );
    5176             : 
    5177             :     // #107251# move focus away if this toolbox was disabled during keyinput
    5178           0 :     if (HasFocus() && mpData->mbKeyInputDisabled && bParentIsContainer)
    5179             :     {
    5180           0 :         sal_uInt16 n = 0;
    5181           0 :         Window *pFocusControl = pParent->ImplGetDlgWindow( n, DLGWINDOW_FIRST );
    5182           0 :         if ( pFocusControl && pFocusControl != this )
    5183           0 :             pFocusControl->ImplControlFocus( GETFOCUS_INIT );
    5184             :     }
    5185             : 
    5186           0 :     mnKeyModifier = 0;
    5187             : 
    5188             :     // #107712#, leave toolbox
    5189           0 :     if( bGrabFocusToDocument )
    5190             :     {
    5191           0 :         GrabFocusToDocument();
    5192           0 :         return;
    5193             :     }
    5194             : 
    5195           0 :     if( bForwardKey )
    5196           0 :         DockingWindow::KeyInput( rKEvt );
    5197             : }
    5198             : 
    5199             : // returns the current toolbox line of the item
    5200           1 : sal_uInt16 ToolBox::ImplGetItemLine( ImplToolItem* pCurrentItem )
    5201             : {
    5202           1 :     std::vector< ImplToolItem >::const_iterator it = mpData->m_aItems.begin();
    5203           1 :     sal_uInt16 nLine = 1;
    5204           2 :     while( it != mpData->m_aItems.end() )
    5205             :     {
    5206           1 :         if ( it->mbBreak )
    5207           0 :             ++nLine;
    5208           1 :         if( &(*it) == pCurrentItem)
    5209           1 :             break;
    5210           0 :         ++it;
    5211             :     }
    5212           1 :     return nLine;
    5213             : }
    5214             : 
    5215             : // returns the first displayable item in the given line
    5216           0 : ImplToolItem* ToolBox::ImplGetFirstValidItem( sal_uInt16 nLine )
    5217             : {
    5218           0 :     if( !nLine || nLine > mnCurLines )
    5219           0 :         return NULL;
    5220             : 
    5221           0 :     nLine--;
    5222             : 
    5223           0 :     std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
    5224           0 :     while( it != mpData->m_aItems.end() )
    5225             :     {
    5226             :         // find correct line
    5227           0 :         if ( it->mbBreak )
    5228           0 :             nLine--;
    5229           0 :         if( !nLine )
    5230             :         {
    5231             :             // find first useful item
    5232           0 :             while( it != mpData->m_aItems.end() && ((it->meType != TOOLBOXITEM_BUTTON) ||
    5233           0 :                 /*!it->mbEnabled ||*/ !it->mbVisible || ImplIsFixedControl( &(*it) )) )
    5234             :             {
    5235           0 :                 ++it;
    5236           0 :                 if( it == mpData->m_aItems.end() || it->mbBreak )
    5237           0 :                     return NULL;    // no valid items in this line
    5238             :             }
    5239           0 :             return &(*it);
    5240             :         }
    5241           0 :         ++it;
    5242             :     }
    5243             : 
    5244           0 :     return (it == mpData->m_aItems.end()) ? NULL : &(*it);
    5245             : }
    5246             : 
    5247           1 : sal_uInt16 ToolBox::ImplFindItemPos( const ImplToolItem* pItem, const std::vector< ImplToolItem >& rList )
    5248             : {
    5249           1 :     if( pItem )
    5250             :     {
    5251             :         sal_uInt16 nPos;
    5252           1 :         for( nPos = 0; nPos < rList.size(); ++nPos )
    5253           1 :             if( &rList[ nPos ] == pItem )
    5254           1 :                 return nPos;
    5255             :     }
    5256           0 :     return TOOLBOX_ITEM_NOTFOUND;
    5257             : }
    5258             : 
    5259           0 : void ToolBox::ChangeHighlight( sal_uInt16 nPos )
    5260             : {
    5261           0 :     if ( nPos < GetItemCount() ) {
    5262           0 :         ImplGrabFocus( 0 );
    5263           0 :         ImplChangeHighlight ( ImplGetItem ( GetItemId ( (sal_uInt16) nPos ) ), false );
    5264             :     }
    5265           0 : }
    5266             : 
    5267           1 : void ToolBox::ImplChangeHighlight( ImplToolItem* pItem, bool bNoGrabFocus )
    5268             : {
    5269             :     // avoid recursion due to focus change
    5270           1 :     if( mbChangingHighlight )
    5271           1 :         return;
    5272             : 
    5273           1 :     mbChangingHighlight = true;
    5274             : 
    5275           1 :     ImplToolItem* pOldItem = NULL;
    5276             : 
    5277           1 :     if ( mnHighItemId )
    5278             :     {
    5279           0 :         ImplHideFocus();
    5280           0 :         sal_uInt16 nPos = GetItemPos( mnHighItemId );
    5281           0 :         pOldItem = ImplGetItem( mnHighItemId );
    5282             :         // #i89962# ImplDrawItem can cause Invalidate/Update
    5283             :         // which will in turn ImplShowFocus again
    5284             :         // set mnHighItemId to 0 already to prevent this hen/egg problem
    5285           0 :         mnHighItemId = 0;
    5286           0 :         ImplDrawItem( nPos, 0 );
    5287           0 :         ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHTOFF, reinterpret_cast< void* >( nPos ) );
    5288             :     }
    5289             : 
    5290           1 :     if( !bNoGrabFocus && pItem != pOldItem && pOldItem && pOldItem->mpWindow )
    5291             :     {
    5292             :         // move focus into toolbox
    5293           0 :         GrabFocus();
    5294             :     }
    5295             : 
    5296           1 :     if( pItem )
    5297             :     {
    5298           1 :         sal_uInt16 aPos = ToolBox::ImplFindItemPos( pItem, mpData->m_aItems );
    5299           1 :         if( aPos != TOOLBOX_ITEM_NOTFOUND)
    5300             :         {
    5301             :             // check for line breaks
    5302           1 :             sal_uInt16 nLine = ImplGetItemLine( pItem );
    5303             : 
    5304           1 :             if( nLine >= mnCurLine + mnVisLines )
    5305             :             {
    5306           0 :                 mnCurLine = nLine - mnVisLines + 1;
    5307           0 :                 mbFormat = true;
    5308             :             }
    5309           1 :             else if ( nLine < mnCurLine )
    5310             :             {
    5311           0 :                 mnCurLine = nLine;
    5312           0 :                 mbFormat = true;
    5313             :             }
    5314             : 
    5315           1 :             if( mbFormat )
    5316             :             {
    5317           1 :                 ImplFormat();
    5318             :             }
    5319             : 
    5320           1 :             mnHighItemId = pItem->mnId;
    5321           1 :             ImplDrawItem( aPos, 2 );    // always use shadow effect (2)
    5322             : 
    5323           1 :             if( mbSelection )
    5324           0 :                 mnCurPos = aPos;
    5325           1 :             ImplShowFocus();
    5326             : 
    5327           1 :             if( pItem->mpWindow )
    5328           0 :                 pItem->mpWindow->GrabFocus();
    5329           1 :             if( pItem != pOldItem )
    5330           1 :                 ImplCallEventListeners( VCLEVENT_TOOLBOX_HIGHLIGHT );
    5331             :         }
    5332             :     }
    5333             :     else
    5334             :     {
    5335           0 :         ImplHideFocus();
    5336           0 :         mnHighItemId = 0;
    5337           0 :         mnCurPos = TOOLBOX_ITEM_NOTFOUND;
    5338             :     }
    5339             : 
    5340           1 :     mbChangingHighlight = false;
    5341             : }
    5342             : 
    5343             : // check for keyboard accessible items
    5344           1 : static bool ImplIsValidItem( const ImplToolItem* pItem, bool bNotClipped )
    5345             : {
    5346           1 :     bool bValid = (pItem && pItem->meType == TOOLBOXITEM_BUTTON && pItem->mbVisible && !ImplIsFixedControl( pItem ));
    5347           1 :     if( bValid && bNotClipped && pItem->IsClipped() )
    5348           0 :         bValid = false;
    5349           1 :     return bValid;
    5350             : }
    5351             : 
    5352           1 : bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle )
    5353             : {
    5354           1 :     ImplToolItem* pToolItem = ImplGetItem( mnHighItemId );
    5355             : 
    5356           1 :     if( !pToolItem || !mnHighItemId )
    5357             :     {
    5358             :         // menubutton highlighted ?
    5359           1 :         if( mpData->mbMenubuttonSelected )
    5360             :         {
    5361           0 :             if( bUp )
    5362             :             {
    5363             :                 // select last valid non-clipped item
    5364           0 :                 std::vector< ImplToolItem >::iterator it = mpData->m_aItems.end();
    5365           0 :                 ImplToolItem* pItem = NULL;
    5366           0 :                 while( it != mpData->m_aItems.begin() )
    5367             :                 {
    5368           0 :                     --it;
    5369           0 :                     if ( ImplIsValidItem( &(*it), true ) )
    5370             :                     {
    5371           0 :                         pItem = &(*it);
    5372           0 :                         break;
    5373             :                     }
    5374             :                 }
    5375           0 :                 ImplDrawMenubutton( this, false );
    5376           0 :                 ImplChangeHighlight( pItem );
    5377             :             }
    5378             :             else
    5379             :             {
    5380             :                 // select first valid non-clipped item
    5381           0 :                 std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
    5382           0 :                 while( it != mpData->m_aItems.end() )
    5383             :                 {
    5384           0 :                     if ( ImplIsValidItem( &(*it), true ) )
    5385           0 :                         break;
    5386           0 :                     ++it;
    5387             :                 }
    5388           0 :                 if( it != mpData->m_aItems.end() )
    5389             :                 {
    5390           0 :                     ImplDrawMenubutton( this, false );
    5391           0 :                     ImplChangeHighlight( &(*it) );
    5392             :                 }
    5393             :             }
    5394           0 :             return true;
    5395             :         }
    5396             : 
    5397           1 :         if( bUp )
    5398             :         {
    5399             :             // Select first valid item
    5400           1 :             std::vector< ImplToolItem >::iterator it = mpData->m_aItems.begin();
    5401           2 :             while( it != mpData->m_aItems.end() )
    5402             :             {
    5403           1 :                 if ( ImplIsValidItem( &(*it), false ) )
    5404           1 :                     break;
    5405           0 :                 ++it;
    5406             :             }
    5407             : 
    5408             :             // select the menu button if a clipped item would be selected
    5409           1 :             if( (it != mpData->m_aItems.end() && &(*it) == ImplGetFirstClippedItem( this )) && IsMenuEnabled() )
    5410             :             {
    5411           0 :                 ImplChangeHighlight( NULL );
    5412           0 :                 ImplDrawMenubutton( this, true );
    5413             :             }
    5414             :             else
    5415           1 :                 ImplChangeHighlight( (it != mpData->m_aItems.end()) ? &(*it) : NULL );
    5416           1 :             return true;
    5417             :         }
    5418             :         else
    5419             :         {
    5420             :             // Select last valid item
    5421             : 
    5422             :             // docked toolbars have the menubutton as last item - if this button is enabled
    5423           0 :             if( IsMenuEnabled() && !ImplIsFloatingMode() )
    5424             :             {
    5425           0 :                 ImplChangeHighlight( NULL );
    5426           0 :                 ImplDrawMenubutton( this, true );
    5427             :             }
    5428             :             else
    5429             :             {
    5430           0 :                 std::vector< ImplToolItem >::iterator it = mpData->m_aItems.end();
    5431           0 :                 ImplToolItem* pItem = NULL;
    5432           0 :                 while( it != mpData->m_aItems.begin() )
    5433             :                 {
    5434           0 :                     --it;
    5435           0 :                     if ( ImplIsValidItem( &(*it), false ) )
    5436             :                     {
    5437           0 :                         pItem = &(*it);
    5438           0 :                         break;
    5439             :                     }
    5440             :                 }
    5441           0 :                 ImplChangeHighlight( pItem );
    5442             :             }
    5443           0 :             return true;
    5444             :         }
    5445             :     }
    5446             : 
    5447           0 :     if( pToolItem )
    5448             :     {
    5449           0 :         sal_uLong pos = ToolBox::ImplFindItemPos( pToolItem, mpData->m_aItems );
    5450           0 :         sal_uLong nCount = mpData->m_aItems.size();
    5451             : 
    5452           0 :         sal_uLong i=0;
    5453           0 :         do
    5454             :         {
    5455           0 :             if( bUp )
    5456             :             {
    5457           0 :                 if( !pos-- )
    5458             :                 {
    5459           0 :                     if( bNoCycle )
    5460           0 :                         return false;
    5461             : 
    5462             :                     // highlight the menu button if it is the last item
    5463           0 :                     if( IsMenuEnabled() && !ImplIsFloatingMode() )
    5464             :                     {
    5465           0 :                         ImplChangeHighlight( NULL );
    5466           0 :                         ImplDrawMenubutton( this, true );
    5467           0 :                         return true;
    5468             :                     }
    5469             :                     else
    5470           0 :                         pos = nCount-1;
    5471             :                 }
    5472             :             }
    5473             :             else
    5474             :             {
    5475           0 :                 if( ++pos >= nCount )
    5476             :                 {
    5477           0 :                     if( bNoCycle )
    5478           0 :                         return false;
    5479             : 
    5480             :                     // highlight the menu button if it is the last item
    5481           0 :                     if( IsMenuEnabled() && !ImplIsFloatingMode() )
    5482             :                     {
    5483           0 :                         ImplChangeHighlight( NULL );
    5484           0 :                         ImplDrawMenubutton( this, true );
    5485           0 :                         return true;
    5486             :                     }
    5487             :                     else
    5488           0 :                         pos = 0;
    5489             :                 }
    5490             :             }
    5491             : 
    5492           0 :             pToolItem = &mpData->m_aItems[pos];
    5493             : 
    5494           0 :             if ( ImplIsValidItem( pToolItem, false ) )
    5495           0 :                 break;
    5496             : 
    5497             :         } while( ++i < nCount);
    5498             : 
    5499           0 :         if( pToolItem->IsClipped() && IsMenuEnabled() )
    5500             :         {
    5501             :             // select the menu button if a clipped item would be selected
    5502           0 :             ImplChangeHighlight( NULL );
    5503           0 :             ImplDrawMenubutton( this, true );
    5504             :         }
    5505           0 :         else if( i != nCount )
    5506           0 :             ImplChangeHighlight( pToolItem );
    5507             :         else
    5508           0 :             return false;
    5509             :     }
    5510           0 :     return true;
    5511             : }
    5512             : 
    5513       10055 : void ToolBox::ImplShowFocus()
    5514             : {
    5515       10055 :     if( mnHighItemId && HasFocus() )
    5516             :     {
    5517           1 :         ImplToolItem* pItem = ImplGetItem( mnHighItemId );
    5518           1 :         if( pItem->mpWindow )
    5519             :         {
    5520           0 :             Window *pWin = pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow ? pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow : pItem->mpWindow;
    5521           0 :             pWin->ImplGetWindowImpl()->mbDrawSelectionBackground = true;
    5522           0 :             pWin->Invalidate( 0 );
    5523             :         }
    5524             :     }
    5525       10055 : }
    5526             : 
    5527           2 : void ToolBox::ImplHideFocus()
    5528             : {
    5529           2 :     if( mnHighItemId )
    5530             :     {
    5531           1 :         ImplToolItem* pItem = ImplGetItem( mnHighItemId );
    5532           1 :         if( pItem->mpWindow )
    5533             :         {
    5534           0 :             Window *pWin = pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow ? pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow : pItem->mpWindow;
    5535           0 :             pWin->ImplGetWindowImpl()->mbDrawSelectionBackground = false;
    5536           0 :             pWin->Invalidate( 0 );
    5537             :         }
    5538             :     }
    5539             : 
    5540           2 :     if ( mpData->mbMenubuttonSelected )
    5541             :     {
    5542             :         // remove highlight from menubutton
    5543           0 :         ImplDrawMenubutton( this, false );
    5544             :     }
    5545           2 : }
    5546             : 
    5547      100025 : void ToolBox::ImplDisableFlatButtons()
    5548             : {
    5549             : #ifdef WNT        // Check in the Windows registry if an AT tool wants no flat toolboxes
    5550             :     static bool bInit = false, bValue = false;
    5551             :     if( ! bInit )
    5552             :     {
    5553             :         bInit = true;
    5554             :         HKEY hkey;
    5555             : 
    5556             :         if( ERROR_SUCCESS == RegOpenKey(HKEY_CURRENT_USER,
    5557             :             "Software\\LibreOffice\\Accessibility\\AtToolSupport",
    5558             :             &hkey) )
    5559             :         {
    5560             :             DWORD dwType = 0;
    5561             :             sal_uInt8 Data[6]; // possible values: "true", "false", "1", "0", DWORD
    5562             :             DWORD cbData = sizeof(Data);
    5563             : 
    5564             :             if( ERROR_SUCCESS == RegQueryValueEx(hkey, "DisableFlatToolboxButtons",
    5565             :                 NULL, &dwType, Data, &cbData) )
    5566             :             {
    5567             :                 switch (dwType)
    5568             :                 {
    5569             :                     case REG_SZ:
    5570             :                         bValue = ((0 == stricmp((const char *) Data, "1")) || (0 == stricmp((const char *) Data, "true")));
    5571             :                         break;
    5572             :                     case REG_DWORD:
    5573             :                         bValue = (bool)(((DWORD *) Data)[0]);
    5574             :                         break;
    5575             :                 }
    5576             :             }
    5577             :             RegCloseKey(hkey);
    5578             :         }
    5579             :     }
    5580             :     if( bValue )
    5581             :         mnOutStyle &= ~TOOLBOX_STYLE_FLAT;
    5582             : #endif
    5583      100025 : }
    5584             : 
    5585           0 : void ToolBox::SetToolbarLayoutMode( ToolBoxLayoutMode eLayout )
    5586             : {
    5587           0 :     if ( meLayoutMode != eLayout )
    5588           0 :        meLayoutMode  = eLayout;
    5589         516 : }
    5590             : 
    5591             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10