/vcl/source/window/toolbox.cxx
C++ | 6336 lines | 4948 code | 840 blank | 548 comment | 1285 complexity | 2d38d34c54a5464c50efa1bc8961fb0d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, GPL-2.0, BSD-3-Clause, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- /*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
- // MARKER(update_precomp.py): autogen include statement, do not remove
- #include "precompiled_vcl.hxx"
- #ifndef _SV_SVSYS_HXX
- #include <svsys.h>
- #endif
- #include <rtl/logfile.hxx>
- #include <tools/list.hxx>
- #include <tools/debug.hxx>
- #ifndef _SV_RC_H
- #include <tools/rc.h>
- #endif
- #include <vcl/svdata.hxx>
- #include <vcl/event.hxx>
- #include <vcl/decoview.hxx>
- #include <vcl/accel.hxx>
- #include <vcl/svapp.hxx>
- #include <vcl/help.hxx>
- #include <vcl/sound.hxx>
- #include <vcl/virdev.hxx>
- #include <vcl/spin.h>
- #include <vcl/toolbox.hxx>
- #include <vcl/toolbox.h>
- #include <vcl/bitmap.hxx>
- #include <tools/poly.hxx>
- #include <vcl/salframe.hxx>
- #include <vcl/mnemonic.hxx>
- #include <vcl/gradient.hxx>
- #include <vcl/menu.hxx>
- #include <vcl/window.h>
- #include <string.h>
- #include <vector>
- #include <math.h>
- // =======================================================================
- DBG_NAMEEX( Window )
- // =======================================================================
- #define SMALLBUTTON_HSIZE 7
- #define SMALLBUTTON_VSIZE 7
- #define SMALLBUTTON_OFF_NORMAL_X 3
- #define SMALLBUTTON_OFF_NORMAL_Y 3
- #define SMALLBUTTON_OFF_CHECKED_X 4
- #define SMALLBUTTON_OFF_CHECKED_Y 4
- #define SMALLBUTTON_OFF_PRESSED_X 5
- #define SMALLBUTTON_OFF_PRESSED_Y 5
- #define OUTBUTTON_SIZE 6
- #define OUTBUTTON_BORDER 4
- #define OUTBUTTON_OFF_NORMAL_X 1
- #define OUTBUTTON_OFF_NORMAL_Y 1
- // -----------------------------------------------------------------------
- #define DEF_MIN_WIDTH 8
- #define DEF_MIN_HEIGHT 8
- #define DEF_TEXT_WIDTH 40
- #define TB_TEXTOFFSET 2
- #define TB_IMAGETEXTOFFSET 3
- #define TB_LINESPACING 3
- #define TB_SPIN_SIZE 14
- #define TB_SPIN_OFFSET 2
- #define TB_NEXT_SIZE 22
- #define TB_NEXT_OFFSET 2
- #define TB_BORDER_OFFSET1 4
- #define TB_BORDER_OFFSET2 2
- #define TB_CUSTOMIZE_OFFSET 2
- #define TB_RESIZE_OFFSET 3
- #define TB_MAXLINES 5
- #define TB_MAXNOSCROLL 32765
- #define TB_MIN_WIN_WIDTH 20
- #define TB_CALCMODE_HORZ 1
- #define TB_CALCMODE_VERT 2
- #define TB_CALCMODE_FLOAT 3
- #define TB_WBLINESIZING (WB_SIZEABLE | WB_DOCKABLE | WB_SCROLL)
- #define TB_MAX_GROUPS 100
- #define DOCK_LINEHSIZE ((USHORT)0x0001)
- #define DOCK_LINEVSIZE ((USHORT)0x0002)
- #define DOCK_LINERIGHT ((USHORT)0x1000)
- #define DOCK_LINEBOTTOM ((USHORT)0x2000)
- #define DOCK_LINELEFT ((USHORT)0x4000)
- #define DOCK_LINETOP ((USHORT)0x8000)
- #define DOCK_LINEOFFSET 3
- // -----------------------------------------------------------------------
- static void ImplDrawButton( ToolBox* pThis, const Rectangle &rRect, USHORT highlight, BOOL bChecked, BOOL bEnabled, BOOL bIsWindow );
- // -----------------------------------------------------------------------
- struct ImplToolSize
- {
- long mnWidth;
- long mnHeight;
- USHORT mnLines;
- };
- struct ImplToolSizeArray
- {
- long mnLength;
- long mnLastEntry;
- ImplToolSize* mpSize;
- ImplToolSizeArray() { mpSize = NULL; mnLength = 0; mnLastEntry = 0; }
- ~ImplToolSizeArray() { if( mpSize ) delete [] mpSize; mnLength = 0; }
- };
- // -----------------------------------------------------------------------
- DECLARE_LIST( ImplTBList, ToolBox* )
- class ImplTBDragMgr
- {
- private:
- ImplTBList* mpBoxList;
- ToolBox* mpDragBox;
- Point maMouseOff;
- Rectangle maRect;
- Rectangle maStartRect;
- Accelerator maAccel;
- long mnMinWidth;
- long mnMaxWidth;
- USHORT mnLineMode;
- USHORT mnStartLines;
- void* mpCustomizeData;
- BOOL mbCustomizeMode;
- BOOL mbResizeMode;
- BOOL mbShowDragRect;
- public:
- ImplTBDragMgr();
- ~ImplTBDragMgr();
- void Insert( ToolBox* pBox )
- { mpBoxList->Insert( pBox ); }
- void Remove( ToolBox* pBox )
- { mpBoxList->Remove( pBox ); }
- ULONG Count() const
- { return mpBoxList->Count(); }
- ToolBox* FindToolBox( const Rectangle& rRect );
- void StartDragging( ToolBox* pDragBox,
- const Point& rPos, const Rectangle& rRect,
- USHORT nLineMode, BOOL bResizeItem,
- void* pData = NULL );
- void Dragging( const Point& rPos );
- void EndDragging( BOOL bOK = TRUE );
- void HideDragRect() { if ( mbShowDragRect ) mpDragBox->HideTracking(); }
- void UpdateDragRect();
- DECL_LINK( SelectHdl, Accelerator* );
- void StartCustomizeMode();
- void EndCustomizeMode();
- BOOL IsCustomizeMode() { return mbCustomizeMode; }
- BOOL IsResizeMode() { return mbResizeMode; }
- };
- // -----------------------------------------------------------------------
- static ImplTBDragMgr* ImplGetTBDragMgr()
- {
- ImplSVData* pSVData = ImplGetSVData();
- if ( !pSVData->maCtrlData.mpTBDragMgr )
- pSVData->maCtrlData.mpTBDragMgr = new ImplTBDragMgr;
- return pSVData->maCtrlData.mpTBDragMgr;
- }
- // -----------------------------------------------------------------------
- int ToolBox::ImplGetDragWidth( ToolBox* pThis )
- {
- #define TB_DRAGWIDTH 8 // the default width of the grip
- int width = TB_DRAGWIDTH;
- if( pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
- {
- ImplControlValue aControlValue;
- Point aPoint;
- Region aContent, aBound;
- Region aArea( Rectangle(aPoint, pThis->GetOutputSizePixel()) );
- if ( pThis->GetNativeControlRegion(CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_VERT : PART_THUMB_HORZ,
- aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
- {
- width = pThis->mbHorz ? aContent.GetBoundRect().GetWidth() : aContent.GetBoundRect().GetHeight();
- }
- }
- return width;
- }
- ButtonType determineButtonType( ImplToolItem* pItem, ButtonType defaultType )
- {
- ButtonType tmpButtonType = defaultType;
- ToolBoxItemBits nBits( pItem->mnBits & 0x300 );
- if ( nBits & TIB_TEXTICON ) // item has custom setting
- {
- tmpButtonType = BUTTON_SYMBOLTEXT;
- if ( nBits == TIB_TEXT_ONLY )
- tmpButtonType = BUTTON_TEXT;
- else if ( nBits == TIB_ICON_ONLY )
- tmpButtonType = BUTTON_SYMBOL;
- }
- return tmpButtonType;
- }
- // -----------------------------------------------------------------------
- void ToolBox::ImplUpdateDragArea( ToolBox *pThis )
- {
- ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
- if( pWrapper )
- {
- if ( pThis->ImplIsFloatingMode() || pWrapper->IsLocked() )
- pWrapper->SetDragArea( Rectangle() );
- else
- {
- if( pThis->meAlign == WINDOWALIGN_TOP || pThis->meAlign == WINDOWALIGN_BOTTOM )
- pWrapper->SetDragArea( Rectangle( 0, 0, ImplGetDragWidth( pThis ), pThis->GetOutputSizePixel().Height() ) );
- else
- pWrapper->SetDragArea( Rectangle( 0, 0, pThis->GetOutputSizePixel().Width(), ImplGetDragWidth( pThis ) ) );
- }
- }
- }
- // -----------------------------------------------------------------------
- void ToolBox::ImplCalcBorder( WindowAlign eAlign, long& rLeft, long& rTop,
- long& rRight, long& rBottom, const ToolBox *pThis )
- {
- if( pThis->ImplIsFloatingMode() || !(pThis->mnWinStyle & WB_BORDER) )
- {
- // no border in floating mode
- rLeft = rTop = rRight = rBottom = 0;
- return;
- }
- ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
- // reserve dragarea only for dockable toolbars
- int dragwidth = ( pWrapper && !pWrapper->IsLocked() ) ? ImplGetDragWidth( (ToolBox*)pThis ) : 0;
- // no shadow border for dockable toolbars
- int borderwidth = pWrapper ? 0: 2;
- if ( eAlign == WINDOWALIGN_TOP )
- {
- rLeft = borderwidth+dragwidth;
- rTop = borderwidth;
- rRight = borderwidth;
- rBottom = 0;
- }
- else if ( eAlign == WINDOWALIGN_LEFT )
- {
- rLeft = borderwidth;
- rTop = borderwidth+dragwidth;
- rRight = 0;
- rBottom = borderwidth;
- }
- else if ( eAlign == WINDOWALIGN_BOTTOM )
- {
- rLeft = borderwidth+dragwidth;
- rTop = 0;
- rRight = borderwidth;
- rBottom = borderwidth;
- }
- else
- {
- rLeft = 0;
- rTop = borderwidth+dragwidth;
- rRight = borderwidth;
- rBottom = borderwidth;
- }
- }
- // -----------------------------------------------------------------------
- static void ImplCheckUpdate( ToolBox *pThis )
- {
- // remove any pending invalidates to avoid
- // have them triggered when paint is locked (see mpData->mbIsPaintLocked)
- // which would result in erasing the background only and not painting any items
- // this must not be done when we're already in Paint()
- // this is only required for transparent toolbars (see ImplDrawTransparentBackground() )
- if( !pThis->IsBackground() && pThis->HasPaintEvent() && !pThis->IsInPaint() )
- pThis->Update();
- }
- // -----------------------------------------------------------------------
- void ToolBox::ImplDrawGrip( ToolBox* pThis )
- {
- ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
- if( pWrapper && !pWrapper->GetDragArea().IsEmpty() )
- {
- // execute pending paint requests
- ImplCheckUpdate( pThis );
- BOOL bNativeOk = FALSE;
- if( pThis->IsNativeControlSupported( CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_HORZ : PART_THUMB_VERT ) )
- {
- ImplControlValue aControlValue;
- ToolbarValue aToolbarValue;
- aToolbarValue.maGripRect = pWrapper->GetDragArea();
- aControlValue.setOptionalVal( (void *)(&aToolbarValue) );
- Point aPt;
- Region aCtrlRegion( Rectangle( aPt, pThis->GetOutputSizePixel() ) );
- ControlState nState = CTRL_STATE_ENABLED;
- bNativeOk = pThis->DrawNativeControl( CTRL_TOOLBAR, pThis->mbHorz ? PART_THUMB_VERT : PART_THUMB_HORZ,
- aCtrlRegion, nState, aControlValue, rtl::OUString() );
- }
- if( bNativeOk )
- return;
- const StyleSettings& rStyleSettings = pThis->GetSettings().GetStyleSettings();
- pThis->SetLineColor( rStyleSettings.GetShadowColor() );
- Size aSz ( pThis->GetOutputSizePixel() );
- if ( pThis->meAlign == WINDOWALIGN_TOP || pThis->meAlign == WINDOWALIGN_BOTTOM )
- {
- int height = (int) (0.6 * aSz.Height() + 0.5);
- int i = (aSz.Height() - height) / 2;
- height += i;
- while( i <= height )
- {
- int x = ImplGetDragWidth( pThis ) / 2;
- pThis->DrawPixel( Point(x, i), rStyleSettings.GetDarkShadowColor() );
- pThis->DrawPixel( Point(x+1, i), rStyleSettings.GetShadowColor() );
- pThis->DrawPixel( Point(x, i+1), rStyleSettings.GetShadowColor() );
- pThis->DrawPixel( Point(x+1, i+1), rStyleSettings.GetFaceColor() );
- pThis->DrawPixel( Point(x+2, i+1), Color(COL_WHITE) );
- pThis->DrawPixel( Point(x+1, i+2), Color(COL_WHITE) );
- pThis->DrawPixel( Point(x+2, i+2), Color(COL_WHITE) );
- i+=4;
- }
- }
- else
- {
- int width = (int) (0.6 * aSz.Width() + 0.5);
- int i = (aSz.Width() - width) / 2;
- width += i;
- while( i <= width )
- {
- int y = ImplGetDragWidth(pThis) / 2;
- pThis->DrawPixel( Point(i, y), rStyleSettings.GetDarkShadowColor() );
- pThis->DrawPixel( Point(i+1, y), rStyleSettings.GetShadowColor() );
- pThis->DrawPixel( Point(i, y+1), rStyleSettings.GetShadowColor() );
- pThis->DrawPixel( Point(i+1, y+1), rStyleSettings.GetFaceColor() );
- pThis->DrawPixel( Point(i+2, y+1), Color(COL_WHITE) );
- pThis->DrawPixel( Point(i+1, y+2), Color(COL_WHITE) );
- pThis->DrawPixel( Point(i+2, y+2), Color(COL_WHITE) );
- i+=4;
- }
- }
- }
- }
- void ToolBox::ImplDrawGradientBackground( ToolBox* pThis, ImplDockingWindowWrapper * )
- {
- // draw a nice gradient
- Color startCol, endCol;
- startCol = pThis->GetSettings().GetStyleSettings().GetFaceGradientColor();
- endCol = pThis->GetSettings().GetStyleSettings().GetFaceColor();
- if( pThis->GetSettings().GetStyleSettings().GetHighContrastMode() )
- // no 'extreme' gradient when high contrast
- startCol = endCol;
- Gradient g;
- g.SetAngle( pThis->mbHorz ? 0 : 900 );
- g.SetStyle( GRADIENT_LINEAR );
- g.SetStartColor( startCol );
- g.SetEndColor( endCol );
- BOOL bLineColor = pThis->IsLineColor();
- Color aOldCol = pThis->GetLineColor();
- pThis->SetLineColor( pThis->GetSettings().GetStyleSettings().GetShadowColor() );
- Size aFullSz( pThis->GetOutputSizePixel() );
- Size aLineSz( aFullSz );
- // use the linesize only when floating
- // full window height is used when docked (single line)
- if( pThis->ImplIsFloatingMode() )
- {
- long nLineSize;
- if( pThis->mbHorz )
- {
- nLineSize = pThis->mnMaxItemHeight;
- if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
- nLineSize = pThis->mnWinHeight;
- aLineSz.Height() = nLineSize;
- }
- else
- {
- nLineSize = pThis->mnMaxItemWidth;
- aLineSz.Width() = nLineSize;
- }
- }
- long nLeft, nTop, nRight, nBottom;
- ImplCalcBorder( pThis->meAlign, nLeft, nTop, nRight, nBottom, pThis );
- Size aTopLineSz( aLineSz );
- Size aBottomLineSz( aLineSz );
- if ( pThis->mnWinStyle & WB_BORDER )
- {
- if( pThis->mbHorz )
- {
- aTopLineSz.Height() += TB_BORDER_OFFSET2 + nTop;
- aBottomLineSz.Height() += TB_BORDER_OFFSET2 + nBottom;
- if( pThis->mnCurLines == 1 )
- aTopLineSz.Height() += TB_BORDER_OFFSET2 + nBottom;
- }
- else
- {
- aTopLineSz.Width() += TB_BORDER_OFFSET1 + nLeft;
- aBottomLineSz.Width() += TB_BORDER_OFFSET1 + nRight;
- if( pThis->mnCurLines == 1 )
- aTopLineSz.Width() += TB_BORDER_OFFSET1 + nLeft;
- }
- }
- if( pThis->mbHorz )
- {
- aTopLineSz.Height() += pThis->mnBorderY;
- if( pThis->mnCurLines == 1 )
- aTopLineSz.Height() += pThis->mnBorderY;
- aBottomLineSz.Height() += pThis->mnBorderY;
- }
- else
- {
- aTopLineSz.Width() += pThis->mnBorderX;
- if( pThis->mnCurLines == 1 )
- aTopLineSz.Width() += pThis->mnBorderX;
- aBottomLineSz.Width() += pThis->mnBorderX;
- }
- if ( pThis->mnWinStyle & WB_LINESPACING )
- {
- if( pThis->mbHorz )
- {
- aLineSz.Height() += TB_LINESPACING;
- if( pThis->mnCurLines > 1 )
- aTopLineSz.Height() += TB_LINESPACING;
- }
- else
- {
- aLineSz.Width() += TB_LINESPACING;
- if( pThis->mnCurLines > 1 )
- aTopLineSz.Width() += TB_LINESPACING;
- }
- }
- if( pThis->mbHorz )
- {
- long y = 0;
- BOOL bDrawSep = FALSE; // pThis->ImplIsFloatingMode() && ( pThis->mnWinStyle & WB_LINESPACING );
- pThis->DrawGradient( Rectangle( 0, y, aTopLineSz.Width(), y+aTopLineSz.Height()), g );
- y += aTopLineSz.Height();
- if ( bDrawSep )
- pThis->DrawLine( Point(0, y-2), Point(aTopLineSz.Width(), y-2) );
- while( y < (pThis->mnDY - aBottomLineSz.Height()) )
- {
- pThis->DrawGradient( Rectangle( 0, y, aLineSz.Width(), y+aLineSz.Height()), g);
- y += aLineSz.Height();
- if ( bDrawSep )
- pThis->DrawLine( Point(0, y-2), Point(aLineSz.Width(), y-2) );
- }
- pThis->DrawGradient( Rectangle( 0, y, aBottomLineSz.Width(), y+aBottomLineSz.Height()), g );
- if ( bDrawSep )
- pThis->DrawLine( Point(0, y-2), Point(aBottomLineSz.Width(), y-2) );
- }
- else
- {
- long x = 0;
- pThis->DrawGradient( Rectangle( x, 0, x+aTopLineSz.Width(), aTopLineSz.Height()), g );
- x += aTopLineSz.Width();
- while( x < (pThis->mnDX - aBottomLineSz.Width()) )
- {
- pThis->DrawGradient( Rectangle( x, 0, x+aLineSz.Width(), aLineSz.Height()), g);
- x += aLineSz.Width();
- }
- pThis->DrawGradient( Rectangle( x, 0, x+aBottomLineSz.Width(), aBottomLineSz.Height()), g );
- }
- if( bLineColor )
- pThis->SetLineColor( aOldCol );
- }
- BOOL ToolBox::ImplDrawNativeBackground( ToolBox* pThis, const Region & )
- {
- // use NWF
- Point aPt;
- Region aCtrlRegion( Rectangle( aPt, pThis->GetOutputSizePixel() ) );
- ControlState nState = CTRL_STATE_ENABLED;
- return pThis->DrawNativeControl( CTRL_TOOLBAR, pThis->mbHorz ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
- aCtrlRegion, nState, ImplControlValue(), rtl::OUString() );
- }
- void ToolBox::ImplDrawTransparentBackground( ToolBox* pThis, const Region &rRegion )
- {
- // just invalidate to trigger paint of the parent
- const bool bOldPaintLock = pThis->mpData->mbIsPaintLocked;
- pThis->mpData->mbIsPaintLocked = true;
- // send an invalidate to the first opaque parent and invalidate the whole hierarchy from there (noclipchildren)
- pThis->Invalidate( rRegion, INVALIDATE_UPDATE|INVALIDATE_NOCLIPCHILDREN );
- pThis->mpData->mbIsPaintLocked = bOldPaintLock;
- }
- void ToolBox::ImplDrawConstantBackground( ToolBox* pThis, const Region &rRegion, BOOL bIsInPopupMode )
- {
- // draw a constant color
- if( !bIsInPopupMode )
- // default background
- pThis->Erase( rRegion.GetBoundRect() );
- else
- {
- // use different color in popupmode
- pThis->DrawWallpaper( rRegion.GetBoundRect(),
- Wallpaper( pThis->GetSettings().GetStyleSettings().GetFaceGradientColor() ) );
- }
- }
- void ToolBox::ImplDrawBackground( ToolBox* pThis, const Rectangle &rRect )
- {
- // execute pending paint requests
- ImplCheckUpdate( pThis );
- ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
- BOOL bIsInPopupMode = pThis->ImplIsInPopupMode();
- Region aPaintRegion( rRect );
- // make sure we do not invalidate/erase too much
- if( pThis->IsInPaint() )
- aPaintRegion.Intersect( pThis->GetActiveClipRegion() );
- pThis->Push( PUSH_CLIPREGION );
- pThis->IntersectClipRegion( aPaintRegion );
- if( !pWrapper /*|| bIsInPopupMode*/ )
- {
- // no gradient for ordinary toolbars (not dockable)
- if( !pThis->IsBackground() && !pThis->IsInPaint() )
- ImplDrawTransparentBackground( pThis, aPaintRegion );
- else
- ImplDrawConstantBackground( pThis, aPaintRegion, bIsInPopupMode );
- }
- else
- {
- // toolbars known to the dockingmanager will be drawn using NWF or a gradient
- // docked toolbars are transparent and NWF is already used in the docking area which is their common background
- // so NWF is used here for floating toolbars only
- BOOL bNativeOk = FALSE;
- if( pThis->ImplIsFloatingMode() && pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL) )
- bNativeOk = ImplDrawNativeBackground( pThis, aPaintRegion );
- if( !bNativeOk )
- {
- if( !pThis->IsBackground() )
- {
- if( !pThis->IsInPaint() )
- ImplDrawTransparentBackground( pThis, aPaintRegion );
- }
- else
- ImplDrawGradientBackground( pThis, pWrapper );
- }
- }
- // restore clip region
- pThis->Pop();
- }
- void ToolBox::ImplErase( ToolBox* pThis, const Rectangle &rRect, BOOL bHighlight, BOOL bHasOpenPopup )
- {
- // the background of non NWF buttons is painted in a constant color
- // to have the same highlight color (transparency in DrawSelectionBackground())
- // items with open popups will also painted using a constant color
- if( !pThis->mpData->mbNativeButtons &&
- (bHighlight || ! (((Window*) pThis)->GetStyle() & WB_3DLOOK ) ) )
- {
- if( (((Window*) pThis)->GetStyle() & WB_3DLOOK ) )
- {
- pThis->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
- pThis->SetLineColor();
- if( bHasOpenPopup )
- // choose the same color as the popup will use
- pThis->SetFillColor( pThis->GetSettings().GetStyleSettings().GetFaceGradientColor() );
- else
- pThis->SetFillColor( Color( COL_WHITE ) );
- pThis->DrawRect( rRect );
- pThis->Pop();
- }
- else
- ImplDrawBackground( pThis, rRect );
- }
- else
- ImplDrawBackground( pThis, rRect );
- }
- void ToolBox::ImplDrawBorder( ToolBox* pWin )
- {
- const StyleSettings& rStyleSettings = pWin->GetSettings().GetStyleSettings();
- long nDX = pWin->mnDX;
- long nDY = pWin->mnDY;
- ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pWin );
- // draw borders for ordinary toolbars only (not dockable)
- if( pWrapper )
- return;
- if ( pWin->meAlign == WINDOWALIGN_BOTTOM )
- {
- // draw bottom border
- pWin->SetLineColor( rStyleSettings.GetShadowColor() );
- pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
- pWin->SetLineColor( rStyleSettings.GetLightColor() );
- pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
- }
- else
- {
- // draw top border
- pWin->SetLineColor( rStyleSettings.GetShadowColor() );
- pWin->DrawLine( Point( 0, 0 ), Point( nDX-1, 0 ) );
- pWin->SetLineColor( rStyleSettings.GetLightColor() );
- pWin->DrawLine( Point( 0, 1 ), Point( nDX-1, 1 ) );
- if ( (pWin->meAlign == WINDOWALIGN_LEFT) || (pWin->meAlign == WINDOWALIGN_RIGHT) )
- {
- if ( pWin->meAlign == WINDOWALIGN_LEFT )
- {
- // draw left-bottom border
- pWin->SetLineColor( rStyleSettings.GetShadowColor() );
- pWin->DrawLine( Point( 0, 0 ), Point( 0, nDY-1 ) );
- pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-1, nDY-2 ) );
- pWin->SetLineColor( rStyleSettings.GetLightColor() );
- pWin->DrawLine( Point( 1, 1 ), Point( 1, nDY-3 ) );
- pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
- }
- else
- {
- // draw right-bottom border
- pWin->SetLineColor( rStyleSettings.GetShadowColor() );
- pWin->DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-3 ) );
- pWin->DrawLine( Point( 0, nDY-2 ), Point( nDX-2, nDY-2 ) );
- pWin->SetLineColor( rStyleSettings.GetLightColor() );
- pWin->DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
- pWin->DrawLine( Point( 0, nDY-1 ), Point( nDX-1, nDY-1 ) );
- }
- }
- }
- if ( pWin->meAlign == WINDOWALIGN_BOTTOM || pWin->meAlign == WINDOWALIGN_TOP )
- {
- // draw right border
- pWin->SetLineColor( rStyleSettings.GetShadowColor() );
- pWin->DrawLine( Point( nDX-2, 0 ), Point( nDX-2, nDY-1 ) );
- pWin->SetLineColor( rStyleSettings.GetLightColor() );
- pWin->DrawLine( Point( nDX-1, 0 ), Point( nDX-1, nDY-1 ) );
- }
- }
- // -----------------------------------------------------------------------
- static bool ImplIsFixedControl( const ImplToolItem *pItem )
- {
- return ( pItem->mpWindow &&
- (pItem->mpWindow->GetType() == WINDOW_FIXEDTEXT ||
- pItem->mpWindow->GetType() == WINDOW_FIXEDLINE ||
- pItem->mpWindow->GetType() == WINDOW_GROUPBOX) );
- }
- // -----------------------------------------------------------------------
- const ImplToolItem *ToolBox::ImplGetFirstClippedItem( const ToolBox* pThis )
- {
- std::vector< ImplToolItem >::const_iterator it;
- it = pThis->mpData->m_aItems.begin();
- while ( it != pThis->mpData->m_aItems.end() )
- {
- if( it->IsClipped() )
- return &(*it);
- ++it;
- }
- return NULL;
- }
- // -----------------------------------------------------------------------
- Size ToolBox::ImplCalcSize( const ToolBox* pThis, USHORT nCalcLines, USHORT nCalcMode )
- {
- long nMax;
- long nLeft = 0;
- long nTop = 0;
- long nRight = 0;
- long nBottom = 0;
- Size aSize;
- WindowAlign eOldAlign = pThis->meAlign;
- BOOL bOldHorz = pThis->mbHorz;
- BOOL bOldAssumeDocked = pThis->mpData->mbAssumeDocked;
- BOOL bOldAssumeFloating = pThis->mpData->mbAssumeFloating;
- if ( nCalcMode )
- {
- BOOL bOldFloatingMode = pThis->ImplIsFloatingMode();
- pThis->mpData->mbAssumeDocked = FALSE;
- pThis->mpData->mbAssumeFloating = FALSE;
- if ( nCalcMode == TB_CALCMODE_HORZ )
- {
- pThis->mpData->mbAssumeDocked = TRUE; // force non-floating mode during calculation
- ImplCalcBorder( WINDOWALIGN_TOP, nLeft, nTop, nRight, nBottom, pThis );
- ((ToolBox*)pThis)->mbHorz = TRUE;
- if ( pThis->mbHorz != bOldHorz )
- ((ToolBox*)pThis)->meAlign = WINDOWALIGN_TOP;
- }
- else if ( nCalcMode == TB_CALCMODE_VERT )
- {
- pThis->mpData->mbAssumeDocked = TRUE; // force non-floating mode during calculation
- ImplCalcBorder( WINDOWALIGN_LEFT, nLeft, nTop, nRight, nBottom, pThis );
- ((ToolBox*)pThis)->mbHorz = FALSE;
- if ( pThis->mbHorz != bOldHorz )
- ((ToolBox*)pThis)->meAlign = WINDOWALIGN_LEFT;
- }
- else if ( nCalcMode == TB_CALCMODE_FLOAT )
- {
- pThis->mpData->mbAssumeFloating = TRUE; // force non-floating mode during calculation
- nLeft = nTop = nRight = nBottom = 0;
- ((ToolBox*)pThis)->mbHorz = TRUE;
- if ( pThis->mbHorz != bOldHorz )
- ((ToolBox*)pThis)->meAlign = WINDOWALIGN_TOP;
- }
- if ( (pThis->meAlign != eOldAlign) || (pThis->mbHorz != bOldHorz) ||
- (pThis->ImplIsFloatingMode() != bOldFloatingMode ) )
- ((ToolBox*)pThis)->mbCalc = TRUE;
- }
- else
- ImplCalcBorder( pThis->meAlign, nLeft, nTop, nRight, nBottom, pThis );
- ((ToolBox*)pThis)->ImplCalcItem();
- if( !nCalcMode && pThis->ImplIsFloatingMode() )
- {
- aSize = ImplCalcFloatSize( ((ToolBox*)pThis), nCalcLines );
- }
- else
- {
- if ( pThis->mbHorz )
- {
- if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
- aSize.Height() = nCalcLines * pThis->mnWinHeight;
- else
- aSize.Height() = nCalcLines * pThis->mnMaxItemHeight;
- if ( pThis->mnWinStyle & WB_LINESPACING )
- aSize.Height() += (nCalcLines-1)*TB_LINESPACING;
- if ( pThis->mnWinStyle & WB_BORDER )
- aSize.Height() += (TB_BORDER_OFFSET2*2) + nTop + nBottom;
- nMax = 0;
- ((ToolBox*)pThis)->ImplCalcBreaks( TB_MAXNOSCROLL, &nMax, pThis->mbHorz );
- if ( nMax )
- aSize.Width() += nMax;
- if ( pThis->mnWinStyle & WB_BORDER )
- aSize.Width() += (TB_BORDER_OFFSET1*2) + nLeft + nRight;
- }
- else
- {
- aSize.Width() = nCalcLines * pThis->mnMaxItemWidth;
- if ( pThis->mnWinStyle & WB_LINESPACING )
- aSize.Width() += (nCalcLines-1)*TB_LINESPACING;
- if ( pThis->mnWinStyle & WB_BORDER )
- aSize.Width() += (TB_BORDER_OFFSET2*2) + nLeft + nRight;
- nMax = 0;
- ((ToolBox*)pThis)->ImplCalcBreaks( TB_MAXNOSCROLL, &nMax, pThis->mbHorz );
- if ( nMax )
- aSize.Height() += nMax;
- if ( pThis->mnWinStyle & WB_BORDER )
- aSize.Height() += (TB_BORDER_OFFSET1*2) + nTop + nBottom;
- }
- }
- // restore previous values
- if ( nCalcMode )
- {
- pThis->mpData->mbAssumeDocked = bOldAssumeDocked;
- pThis->mpData->mbAssumeFloating = bOldAssumeFloating;
- if ( (pThis->meAlign != eOldAlign) || (pThis->mbHorz != bOldHorz) )
- {
- ((ToolBox*)pThis)->meAlign = eOldAlign;
- ((ToolBox*)pThis)->mbHorz = bOldHorz;
- ((ToolBox*)pThis)->mbCalc = TRUE;
- }
- }
- if ( aSize.Width() )
- aSize.Width() += pThis->mnBorderX*2;
- if ( aSize.Height() )
- aSize.Height() += pThis->mnBorderY*2;
- return aSize;
- }
- // -----------------------------------------------------------------------
- void ToolBox::ImplCalcFloatSizes( ToolBox* pThis )
- {
- if ( pThis->mpFloatSizeAry )
- return;
- // calculate the minimal size, i.e. where the biggest item just fits
- long nCalcSize = 0;
- std::vector< ImplToolItem >::const_iterator it;
- it = pThis->mpData->m_aItems.begin();
- while ( it != pThis->mpData->m_aItems.end() )
- {
- if ( it->mbVisible )
- {
- if ( it->mpWindow )
- {
- long nTempSize = it->mpWindow->GetSizePixel().Width();
- if ( nTempSize > nCalcSize )
- nCalcSize = nTempSize;
- }
- else
- {
- if( it->maItemSize.Width() > nCalcSize )
- nCalcSize = it->maItemSize.Width();
- }
- }
- ++it;
- }
- // calc an upper bound for ImplCalcBreaks below
- long upperBoundWidth = nCalcSize * pThis->mpData->m_aItems.size();
- USHORT i;
- USHORT nLines;
- USHORT nCalcLines;
- USHORT nTempLines;
- long nHeight;
- long nMaxLineWidth;
- nCalcLines = pThis->ImplCalcBreaks( nCalcSize, &nMaxLineWidth, TRUE );
- pThis->mpFloatSizeAry = new ImplToolSizeArray;
- pThis->mpFloatSizeAry->mpSize = new ImplToolSize[nCalcLines];
- pThis->mpFloatSizeAry->mnLength = nCalcLines;
- memset( pThis->mpFloatSizeAry->mpSize, 0, sizeof( ImplToolSize )*nCalcLines );
- i = 0;
- nTempLines = nLines = nCalcLines;
- while ( nLines )
- {
- nHeight = ImplCalcSize( pThis, nTempLines, TB_CALCMODE_FLOAT ).Height();
- pThis->mpFloatSizeAry->mnLastEntry = i;
- pThis->mpFloatSizeAry->mpSize[i].mnHeight = nHeight;
- pThis->mpFloatSizeAry->mpSize[i].mnLines = nTempLines;
- pThis->mpFloatSizeAry->mpSize[i].mnWidth = nMaxLineWidth+(TB_BORDER_OFFSET1*2);
- nLines--;
- if ( nLines )
- {
- do
- {
- nCalcSize += pThis->mnMaxItemWidth;
- nTempLines = pThis->ImplCalcBreaks( nCalcSize, &nMaxLineWidth, TRUE );
- }
- while ( (nCalcSize < upperBoundWidth) && (nLines < nTempLines) && (nTempLines != 1) );
- if ( nTempLines < nLines )
- nLines = nTempLines;
- }
- i++;
- }
- }
- // -----------------------------------------------------------------------
- Size ToolBox::ImplCalcFloatSize( ToolBox* pThis, USHORT& rLines )
- {
- ImplCalcFloatSizes( pThis );
- if ( !rLines )
- {
- rLines = pThis->mnFloatLines;
- if ( !rLines )
- rLines = pThis->mnLines;
- }
- USHORT i = 0;
- while ( i < pThis->mpFloatSizeAry->mnLastEntry &&
- rLines < pThis->mpFloatSizeAry->mpSize[i].mnLines )
- i++;
- Size aSize( pThis->mpFloatSizeAry->mpSize[i].mnWidth,
- pThis->mpFloatSizeAry->mpSize[i].mnHeight );
- rLines = pThis->mpFloatSizeAry->mpSize[i].mnLines;
- if ( pThis->maNextToolBoxStr.Len() && pThis->mbScroll )
- aSize.Width() += TB_NEXT_SIZE-TB_NEXT_OFFSET;
- return aSize;
- }
- // -----------------------------------------------------------------------
- void ToolBox::ImplCalcMinMaxFloatSize( ToolBox* pThis, Size& rMinSize, Size& rMaxSize )
- {
- ImplCalcFloatSizes( pThis );
- USHORT i = 0;
- rMinSize = Size( pThis->mpFloatSizeAry->mpSize[i].mnWidth, pThis->mpFloatSizeAry->mpSize[i].mnHeight );
- rMaxSize = Size( pThis->mpFloatSizeAry->mpSize[i].mnWidth, pThis->mpFloatSizeAry->mpSize[i].mnHeight );
- while ( ++i <= pThis->mpFloatSizeAry->mnLastEntry )
- {
- if( pThis->mpFloatSizeAry->mpSize[i].mnWidth < rMinSize.Width() )
- rMinSize.Width() = pThis->mpFloatSizeAry->mpSize[i].mnWidth;
- if( pThis->mpFloatSizeAry->mpSize[i].mnHeight < rMinSize.Height() )
- rMinSize.Height() = pThis->mpFloatSizeAry->mpSize[i].mnHeight;
- if( pThis->mpFloatSizeAry->mpSize[i].mnWidth > rMaxSize.Width() )
- rMaxSize.Width() = pThis->mpFloatSizeAry->mpSize[i].mnWidth;
- if( pThis->mpFloatSizeAry->mpSize[i].mnHeight > rMaxSize.Height() )
- rMaxSize.Height() = pThis->mpFloatSizeAry->mpSize[i].mnHeight;
- }
- }
- void ToolBox::ImplSetMinMaxFloatSize( ToolBox *pThis )
- {
- ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pThis );
- Size aMinSize, aMaxSize;
- ImplCalcMinMaxFloatSize( pThis, aMinSize, aMaxSize );
- if( pWrapper )
- {
- pWrapper->SetMinOutputSizePixel( aMinSize );
- pWrapper->SetMaxOutputSizePixel( aMaxSize );
- pWrapper->ShowTitleButton( TITLE_BUTTON_MENU, ( pThis->GetMenuType() & TOOLBOX_MENUTYPE_CUSTOMIZE) ? TRUE : FALSE );
- }
- else
- {
- // TODO: change SetMinOutputSizePixel to be not inline
- pThis->SetMinOutputSizePixel( aMinSize );
- pThis->SetMaxOutputSizePixel( aMaxSize );
- }
- }
- // -----------------------------------------------------------------------
- USHORT ToolBox::ImplCalcLines( ToolBox* pThis, long nToolSize )
- {
- long nLineHeight;
- if ( pThis->mbHorz )
- {
- if ( pThis->mnWinHeight > pThis->mnMaxItemHeight )
- nLineHeight = pThis->mnWinHeight;
- else
- nLineHeight = pThis->mnMaxItemHeight;
- }
- else
- nLineHeight = pThis->mnMaxItemWidth;
- if ( pThis->mnWinStyle & WB_BORDER )
- nToolSize -= TB_BORDER_OFFSET2*2;
- if ( pThis->mnWinStyle & WB_LINESPACING )
- {
- nLineHeight += TB_LINESPACING;
- nToolSize += TB_LINESPACING;
- }
-
- // #i91917# always report at least one line
- long nLines = nToolSize/nLineHeight;
- if( nLines < 1 )
- nLines = 1;
-
- return static_cast<USHORT>(nLines);
- }
- // -----------------------------------------------------------------------
- USHORT ToolBox::ImplTestLineSize( ToolBox* pThis, const Point& rPos )
- {
- if ( !pThis->ImplIsFloatingMode() &&
- (!pThis->mbScroll || (pThis->mnLines > 1) || (pThis->mnCurLines > pThis->mnVisLines)) )
- {
- WindowAlign eAlign = pThis->GetAlign();
- if ( eAlign == WINDOWALIGN_LEFT )
- {
- if ( rPos.X() > pThis->mnDX-DOCK_LINEOFFSET )
- return DOCK_LINEHSIZE | DOCK_LINERIGHT;
- }
- else if ( eAlign == WINDOWALIGN_TOP )
- {
- if ( rPos.Y() > pThis->mnDY-DOCK_LINEOFFSET )
- return DOCK_LINEVSIZE | DOCK_LINEBOTTOM;
- }
- else if ( eAlign == WINDOWALIGN_RIGHT )
- {
- if ( rPos.X() < DOCK_LINEOFFSET )
- return DOCK_LINEHSIZE | DOCK_LINELEFT;
- }
- else if ( eAlign == WINDOWALIGN_BOTTOM )
- {
- if ( rPos.Y() < DOCK_LINEOFFSET )
- return DOCK_LINEVSIZE | DOCK_LINETOP;
- }
- }
- return 0;
- }
- // -----------------------------------------------------------------------
- void ToolBox::ImplLineSizing( ToolBox* pThis, const Point& rPos, Rectangle& rRect,
- USHORT nLineMode )
- {
- BOOL mbHorz;
- long nOneLineSize;
- long nCurSize;
- long nMaxSize;
- long nSize;
- Size aSize;
- if ( nLineMode & DOCK_LINERIGHT )
- {
- nCurSize = rPos.X() - rRect.Left();
- mbHorz = FALSE;
- }
- else if ( nLineMode & DOCK_LINEBOTTOM )
- {
- nCurSize = rPos.Y() - rRect.Top();
- mbHorz = TRUE;
- }
- else if ( nLineMode & DOCK_LINELEFT )
- {
- nCurSize = rRect.Right() - rPos.X();
- mbHorz = FALSE;
- }
- else if ( nLineMode & DOCK_LINETOP )
- {
- nCurSize = rRect.Bottom() - rPos.Y();
- mbHorz = TRUE;
- }
- else {
- DBG_ERROR( "ImplLineSizing: Trailing else" );
- nCurSize = 0;
- mbHorz = FALSE;
- }
- Size aWinSize = pThis->GetSizePixel();
- USHORT nMaxLines = (pThis->mnLines > pThis->mnCurLines) ? pThis->mnLines : pThis->mnCurLines;
- if ( nMaxLines > TB_MAXLINES )
- nMaxLines = TB_MAXLINES;
- if ( mbHorz )
- {
- nOneLineSize = ImplCalcSize( pThis, 1 ).Height();
- nMaxSize = pThis->maOutDockRect.GetHeight() - 20;
- if ( nMaxSize < aWinSize.Height() )
- nMaxSize = aWinSize.Height();
- }
- else
- {
- nOneLineSize = ImplCalcSize( pThis, 1 ).Width();
- nMaxSize = pThis->maOutDockRect.GetWidth() - 20;
- if ( nMaxSize < aWinSize.Width() )
- nMaxSize = aWinSize.Width();
- }
- USHORT i = 1;
- if ( nCurSize <= nOneLineSize )
- nSize = nOneLineSize;
- else
- {
- nSize = 0;
- while ( (nSize < nCurSize) && (i < nMaxLines) )
- {
- i++;
- aSize = ImplCalcSize( pThis, i );
- if ( mbHorz )
- nSize = aSize.Height();
- else
- nSize = aSize.Width();
- if ( nSize > nMaxSize )
- {
- i--;
- aSize = ImplCalcSize( pThis, i );
- if ( mbHorz )
- nSize = aSize.Height();
- else
- nSize = aSize.Width();
- break;
- }
- }
- }
- if ( nLineMode & DOCK_LINERIGHT )
- rRect.Right() = rRect.Left()+nSize-1;
- else if ( nLineMode & DOCK_LINEBOTTOM )
- rRect.Bottom() = rRect.Top()+nSize-1;
- else if ( nLineMode & DOCK_LINELEFT )
- rRect.Left() = rRect.Right()-nSize;
- else //if ( nLineMode & DOCK_LINETOP )
- rRect.Top() = rRect.Bottom()-nSize;
- pThis->mnDockLines = i;
- }
- // -----------------------------------------------------------------------
- USHORT ToolBox::ImplFindItemPos( ToolBox* pBox, const Point& rPos )
- {
- USHORT nPos = 0;
- long nLast = 0;
- Point aPos = rPos;
- Size aSize( pBox->mnDX, pBox->mnDY );
- if ( aPos.X() > aSize.Width()-TB_BORDER_OFFSET1 )
- aPos.X() = aSize.Width()-TB_BORDER_OFFSET1;
- if ( aPos.Y() > aSize.Height()-TB_BORDER_OFFSET1 )
- aPos.Y() = aSize.Height()-TB_BORDER_OFFSET1;
- // Item suchen, das geklickt wurde
- std::vector< ImplToolItem >::const_iterator it = pBox->mpData->m_aItems.begin();
- while ( it != pBox->mpData->m_aItems.end() )
- {
- if ( it->mbVisible )
- {
- if ( nLast || !it->maRect.IsEmpty() )
- {
- if ( pBox->mbHorz )
- {
- if ( nLast &&
- ((nLast < it->maRect.Top()) || it->maRect.IsEmpty()) )
- return nPos;
- if ( aPos.Y() <= it->maRect.Bottom() )
- {
- if ( aPos.X() < it->maRect.Left() )
- return nPos;
- else if ( aPos.X() < it->maRect.Right() )
- return nPos+1;
- else if ( !nLast )
- nLast = it->maRect.Bottom();
- }
- }
- else
- {
- if ( nLast &&
- ((nLast < it->maRect.Left()) || it->maRect.IsEmpty()) )
- return nPos;
- if ( aPos.X() <= it->maRect.Right() )
- {
- if ( aPos.Y() < it->maRect.Top() )
- return nPos;
- else if ( aPos.Y() < it->maRect.Bottom() )
- return nPos+1;
- else if ( !nLast )
- nLast = it->maRect.Right();
- }
- }
- }
- }
- nPos++;
- ++it;
- }
- return nPos;
- }
- // -----------------------------------------------------------------------
- ImplTBDragMgr::ImplTBDragMgr()
- {
- mpBoxList = new ImplTBList( 4, 4 );
- mnLineMode = 0;
- mnStartLines = 0;
- mbCustomizeMode = FALSE;
- mbResizeMode = FALSE;
- mbShowDragRect = FALSE;
- mpDragBox = NULL;
- maAccel.InsertItem( KEY_RETURN, KeyCode( KEY_RETURN ) );
- maAccel.InsertItem( KEY_ESCAPE, KeyCode( KEY_ESCAPE ) );
- maAccel.SetSelectHdl( LINK( this, ImplTBDragMgr, SelectHdl ) );
- }
- // -----------------------------------------------------------------------
- ImplTBDragMgr::~ImplTBDragMgr()
- {
- delete mpBoxList;
- }
- // -----------------------------------------------------------------------
- ToolBox* ImplTBDragMgr::FindToolBox( const Rectangle& rRect )
- {
- ToolBox* pBox = mpBoxList->First();
- while ( pBox )
- {
- /*
- * FIXME: since we can have multiple frames now we cannot
- * find the drag target by its position alone.
- * As long as the toolbar config dialogue is not a system window
- * this works in one frame only anyway. If the dialogue
- * changes to a system window, we need a new implementation here
- */
- if ( pBox->IsReallyVisible() && pBox->ImplGetWindowImpl()->mpFrame == mpDragBox->ImplGetWindowImpl()->mpFrame )
- {
- if ( !pBox->ImplIsFloatingMode() )
- {
- Point aPos = pBox->GetPosPixel();
- aPos = pBox->GetParent()->OutputToScreenPixel( aPos );
- Rectangle aTempRect( aPos, pBox->GetSizePixel() );
- if ( aTempRect.IsOver( rRect ) )
- return pBox;
- }
- }
- pBox = mpBoxList->Next();
- }
- return pBox;
- }
- // -----------------------------------------------------------------------
- void ImplTBDragMgr::StartDragging( ToolBox* pToolBox,
- const Point& rPos, const Rectangle& rRect,
- USHORT nDragLineMode, BOOL bResizeItem,
- void* pData )
- {
- mpDragBox = pToolBox;
- pToolBox->CaptureMouse();
- pToolBox->mbDragging = TRUE;
- Application::InsertAccel( &maAccel );
- if ( nDragLineMode )
- {
- mnLineMode = nDragLineMode;
- mnStartLines = pToolBox->mnDockLines;
- }
- else
- {
- mpCustomizeData = pData;
- mbResizeMode = bResizeItem;
- pToolBox->Activate();
- pToolBox->mnCurItemId = pToolBox->mnConfigItem;
- pToolBox->Highlight();
- pToolBox->mnCurItemId = 0;
- if ( mbResizeMode )
- {
- if ( rRect.GetWidth() < TB_MIN_WIN_WIDTH )
- mnMinWidth = rRect.GetWidth();
- else
- mnMinWidth = TB_MIN_WIN_WIDTH;
- mnMaxWidth = pToolBox->GetSizePixel().Width()-rRect.Left()-
- TB_SPIN_SIZE-TB_BORDER_OFFSET1-(TB_SPIN_OFFSET*2);
- }
- }
- // MouseOffset berechnen
- maMouseOff.X() = rRect.Left() - rPos.X();
- maMouseOff.Y() = rRect.Top() - rPos.Y();
- maRect = rRect;
- maStartRect = rRect;
- mbShowDragRect = TRUE;
- pToolBox->ShowTracking( maRect );
- }
- // -----------------------------------------------------------------------
- void ImplTBDragMgr::Dragging( const Point& rPos )
- {
- if ( mnLineMode )
- {
- ToolBox::ImplLineSizing( mpDragBox, rPos, maRect, mnLineMode );
- Point aOff = mpDragBox->OutputToScreenPixel( Point() );
- maRect.Move( aOff.X(), aOff.Y() );
- mpDragBox->Docking( rPos, maRect );
- maRect.Move( -aOff.X(), -aOff.Y() );
- mpDragBox->ShowTracking( maRect );
- }
- else
- {
- if ( mbResizeMode )
- {
- long nXOff = rPos.X()-maStartRect.Left();
- nXOff += maMouseOff.X()+(maStartRect.Right()-maStartRect.Left());
- if ( nXOff < mnMinWidth )
- nXOff = mnMinWidth;
- if ( nXOff > mnMaxWidth )
- nXOff = mnMaxWidth;
- maRect.Right() = maStartRect.Left()+nXOff;
- }
- else
- {
- maRect.SetPos( rPos );
- maRect.Move( maMouseOff.X(), maMouseOff.Y() );
- }
- mpDragBox->ShowTracking( maRect );
- }
- }
- // -----------------------------------------------------------------------
- void ImplTBDragMgr::EndDragging( BOOL bOK )
- {
- mpDragBox->HideTracking();
- mpDragBox->ReleaseMouse();
- mpDragBox->mbDragging = FALSE;
- mbShowDragRect = FALSE;
- Application::RemoveAccel( &maAccel );
- if ( mnLineMode )
- {
- if ( !bOK )
- {
- mpDragBox->mnDockLines = mnStartLines;
- mpDragBox->EndDocking( maStartRect, FALSE );
- }
- else
- mpDragBox->EndDocking( maRect, FALSE );
- mnLineMode = 0;
- mnStartLines = 0;
- }
- else
- {
- USHORT nTempItem = mpDragBox->mnConfigItem;
- if ( nTempItem )
- {
- mpDragBox->mnConfigItem = 0;
- if ( !mbResizeMode )
- mpDragBox->Invalidate( mpDragBox->GetItemRect( nTempItem ) );
- }
- if ( bOK && (maRect != maStartRect) )
- {
- if ( mbResizeMode )
- {
- ImplToolItem* pItem = mpDragBox->ImplGetItem( nTempItem );
- Size aSize = pItem->mpWindow->GetSizePixel();
- aSize.Width() = maRect.GetWidth();
- pItem->mpWindow->SetSizePixel( aSize );
- // ToolBox neu brechnen und neu ausgeben
- mpDragBox->ImplInvalidate( TRUE );
- mpDragBox->Customize( ToolBoxCustomizeEvent( mpDragBox, nTempItem,
- TOOLBOX_CUSTOMIZE_RESIZE,
- mpCustomizeData ) );
- }
- else
- {
- Point aOff = mpDragBox->OutputToScreenPixel( Point() );
- Rectangle aScreenRect( maRect );
- aScreenRect.Move( aOff.X(), aOff.Y() );
- ToolBox* pDropBox = FindToolBox( aScreenRect );
- if ( pDropBox )
- {
- // Such-Position bestimmen
- Point aPos;
- if ( pDropBox->mbHorz )
- {
- aPos.X() = aScreenRect.Left()-TB_CUSTOMIZE_OFFSET;
- aPos.Y() = aScreenRect.Center().Y();
- }
- else
- {
- aPos.X() = aScreenRect.Center().X();
- aPos.Y() = aScreenRect.Top()-TB_CUSTOMIZE_OFFSET;
- }
- aPos = pDropBox->ScreenToOutputPixel( aPos );
- USHORT nPos = ToolBox::ImplFindItemPos( pDropBox, aPos );
- mpDragBox->Customize( ToolBoxCustomizeEvent( pDropBox, nTempItem,
- nPos, mpCustomizeData ) );
- }
- else
- {
- mpDragBox->Customize( ToolBoxCustomizeEvent( NULL, nTempItem,
- 0, mpCustomizeData ) );
- }
- }
- }
- mpCustomizeData = NULL;
- mbResizeMode = FALSE;
- mpDragBox->Deactivate();
- }
- mpDragBox = NULL;
- }
- // -----------------------------------------------------------------------
- void ImplTBDragMgr::UpdateDragRect()
- {
- // Nur Updaten, wenn wir schon im Dragging sind
- if ( !mbShowDragRect )
- return;
- mpDragBox->ShowTracking( maRect );
- }
- // -----------------------------------------------------------------------
- IMPL_LINK( ImplTBDragMgr, SelectHdl, Accelerator*, pAccel )
- {
- if ( pAccel->GetCurItemId() == KEY_ESCAPE )
- EndDragging( FALSE );
- else
- EndDragging( TRUE );
- return TRUE;
- }
- // -----------------------------------------------------------------------
- void ImplTBDragMgr::StartC…
Large files files are truncated, but you can click here to view the full file