/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
// reserve DragArea only for dockable toolbars int dragwidth = ( pWrapper && !pWrapper->IsLocked() ) ? ImplGetDragWidth() : 0;
// no shadow border for dockable toolbars and toolbars with WB_NOSHADOW bit set, e.g. Calc's formulabar int borderwidth = ( pWrapper || mnWinStyle & WB_NOSHADOW ) ? 0 : 2;
void ToolBox::ImplCheckUpdate()
{ // 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( !IsBackground() && HasPaintEvent() && !IsInPaint() )
PaintImmediately();
}
void ToolBox::ImplDrawGradientBackground(vcl::RenderContext& rRenderContext)
{ // draw a nice gradient
Color startCol, endCol; const StyleSettings rSettings = rRenderContext.GetSettings().GetStyleSettings();
startCol = rSettings.GetFaceGradientColor();
endCol = rSettings.GetFaceColor(); if (rSettings.GetHighContrastMode()) // no 'extreme' gradient when high contrast
startCol = endCol;
// use the linesize only when floating // full window height is used when docked (single line) if (ImplIsFloatingMode())
{
tools::Long nLineSize; if (mbHorz)
{
nLineSize = mnMaxItemHeight; if (mnWinHeight > mnMaxItemHeight)
nLineSize = mnWinHeight;
if (mnCurLines == 1)
aTopLineSz.AdjustWidth(TB_BORDER_OFFSET1 + nLeft );
}
}
if (mbLineSpacing)
{ if (mbHorz)
{
aLineSz.AdjustHeight(TB_LINESPACING ); if (mnCurLines > 1)
aTopLineSz.AdjustHeight(TB_LINESPACING );
} else
{
aLineSz.AdjustWidth(TB_LINESPACING ); if (mnCurLines > 1)
aTopLineSz.AdjustWidth(TB_LINESPACING );
}
}
if (mbHorz)
{
tools::Long y = 0;
rRenderContext.DrawGradient(tools::Rectangle(0, y, aTopLineSz.Width(), y + aTopLineSz.Height()), g);
y += aTopLineSz.Height();
while (y < (mnDY - aBottomLineSz.Height()))
{
rRenderContext.DrawGradient(tools::Rectangle(0, y, aLineSz.Width(), y + aLineSz.Height()), g);
y += aLineSz.Height();
}
rRenderContext.DrawGradient(tools::Rectangle(0, y, aBottomLineSz.Width(), y + aBottomLineSz.Height()), g);
} else
{
tools::Long x = 0;
rRenderContext.DrawGradient(tools::Rectangle(x, 0, x + aTopLineSz.Width(), aTopLineSz.Height()), g);
x += aTopLineSz.Width();
while (x < (mnDX - aBottomLineSz.Width()))
{
rRenderContext.DrawGradient(tools::Rectangle(x, 0, x + aLineSz.Width(), aLineSz.Height()), g);
x += aLineSz.Width();
}
rRenderContext.DrawGradient(tools::Rectangle( x, 0, x + aBottomLineSz.Width(), aBottomLineSz.Height()), g);
}
void ToolBox::ImplDrawTransparentBackground(const vcl::Region &rRegion)
{ // just invalidate to trigger paint of the parent constbool bOldPaintLock = mpData->mbIsPaintLocked;
mpData->mbIsPaintLocked = true;
// send an invalidate to the first opaque parent and invalidate the whole hierarchy from there (noclipchildren)
Invalidate(rRegion, InvalidateFlags::Update | InvalidateFlags::NoClipChildren);
mpData->mbIsPaintLocked = bOldPaintLock;
}
void ToolBox::ImplDrawConstantBackground(vcl::RenderContext& rRenderContext, const vcl::Region &rRegion, bool bIsInPopupMode)
{ // draw a constant color if (!bIsInPopupMode)
{ // default background
rRenderContext.Erase(rRegion.GetBoundRect());
} else
{ // use different color in popupmode const StyleSettings rSettings = rRenderContext.GetSettings().GetStyleSettings();
Wallpaper aWallpaper(rSettings.GetFaceGradientColor());
rRenderContext.DrawWallpaper(rRegion.GetBoundRect(), aWallpaper);
}
}
if (!pWrapper)
{ // no gradient for ordinary toolbars (not dockable) if( !IsBackground() && !IsInPaint() )
ImplDrawTransparentBackground(aPaintRegion); else
ImplDrawConstantBackground(rRenderContext, 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( ImplIsFloatingMode() && rRenderContext.IsNativeControlSupported( ControlType::Toolbar, ControlPart::Entire) )
bNativeOk = ImplDrawNativeBackground(rRenderContext); if (!bNativeOk)
{ const StyleSettings rSetting = Application::GetSettings().GetStyleSettings(); if (!IsBackground())
{ if (!IsInPaint())
ImplDrawTransparentBackground(aPaintRegion);
} else
ImplDrawGradientBackground(rRenderContext);
}
}
// restore clip region
rRenderContext.Pop();
}
void ToolBox::ImplErase(vcl::RenderContext& rRenderContext, const tools::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 (!mpData->mbNativeButtons &&
(bHighlight || !(GetStyle() & WB_3DLOOK)))
{ if (GetStyle() & WB_3DLOOK)
{
rRenderContext.Push(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR);
rRenderContext.SetLineColor(); if (bHasOpenPopup) // choose the same color as the popup will use
rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetFaceColor()); else
rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetWindowColor());
// dockingwindow's ImplInit removes some bits, so restore them here to allow keyboard handling for toolbars
ImplGetWindowImpl()->mnStyle |= WB_TABSTOP|WB_NODIALOGCONTROL; // always set WB_TABSTOP for ToolBars
ImplGetWindowImpl()->mnStyle &= ~WB_DIALOGCONTROL;
// calculate size of floating windows and switch if the // toolbox is initially in floating mode if ( ImplIsFloatingMode() )
mbHorz = true; else
Resize();
if (!(GetStyle() & WB_HIDE))
Show();
}
ToolBox::~ToolBox()
{
disposeOnce();
}
void ToolBox::dispose()
{ // #103005# make sure our activate/deactivate balance is right while( mnActivateCount > 0 )
Deactivate();
// terminate popupmode if the floating window is // still connected if ( mpFloatWin )
mpFloatWin->EndPopupMode( FloatWinPopupEndFlags::Cancel );
mpFloatWin = nullptr;
// also calculate the area for comboboxes, drop down list boxes and spinfields // as these are often inserted into toolboxes; set mnWinHeight to the // greater of those values to prevent toolbar flickering (#i103385#)
aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
aReg = aRect; if( GetNativeControlRegion( ControlType::Combobox, ControlPart::Entire,
aReg,
ControlState::ENABLED | ControlState::ROLLOVER,
aVal,
aNativeBounds, aNativeContent ) )
{
aRect = aNativeBounds; if( aRect.GetHeight() > mnWinHeight )
mnWinHeight = aRect.GetHeight();
}
aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
aReg = aRect; if( GetNativeControlRegion( ControlType::Listbox, ControlPart::Entire,
aReg,
ControlState::ENABLED | ControlState::ROLLOVER,
aVal,
aNativeBounds, aNativeContent ) )
{
aRect = aNativeBounds; if( aRect.GetHeight() > mnWinHeight )
mnWinHeight = aRect.GetHeight();
}
aRect = tools::Rectangle( Point( 0, 0 ), Size( nMinWidth, nMinHeight ) );
aReg = aRect; if( GetNativeControlRegion( ControlType::Spinbox, ControlPart::Entire,
aReg,
ControlState::ENABLED | ControlState::ROLLOVER,
aVal,
aNativeBounds, aNativeContent ) )
{
aRect = aNativeBounds; if( aRect.GetHeight() > mnWinHeight )
mnWinHeight = aRect.GetHeight();
}
}
if ( ! mpData->m_aItems.empty() )
{ for (auto & item : mpData->m_aItems)
{
item.mbVisibleText = false; // indicates if text will definitely be drawn, influences dropdown pos
if ( meTextPosition == ToolBoxTextPosition::Right )
{ // leave space between image and text if( bText )
item.maItemSize.AdjustWidth(TB_IMAGETEXTOFFSET );
// image and text side by side
item.maItemSize.AdjustWidth(item.maImage.GetSizePixel().Width() ); if ( item.maImage.GetSizePixel().Height() > item.maItemSize.Height() )
item.maItemSize.setHeight( item.maImage.GetSizePixel().Height() );
} else
{ // leave space between image and text if( bText )
item.maItemSize.AdjustHeight(TB_IMAGETEXTOFFSET );
// text below image
item.maItemSize.AdjustHeight(item.maImage.GetSizePixel().Height() ); if ( item.maImage.GetSizePixel().Width() > item.maItemSize.Width() )
item.maItemSize.setWidth( item.maImage.GetSizePixel().Width() );
}
item.mbVisibleText = bText;
}
} else
{ // no image and no text
item.maItemSize = Size( nDefWidth, nDefHeight );
item.mbEmptyBtn = true;
}
// save the content size
item.maContentSize = item.maItemSize;
// if required, take window height into consideration if ( item.mpWindow )
{
tools::Long nHeight = item.mpWindow->GetSizePixel().Height(); if ( nHeight > mnWinHeight )
mnWinHeight = nHeight;
}
// add in drop down arrow if( item.mnBits & ToolBoxItemBits::DROPDOWN )
{
item.maItemSize.AdjustWidth(nDropDownArrowWidth );
item.mnDropDownArrowWidth = nDropDownArrowWidth;
}
// text items will be rotated in vertical mode // -> swap width and height if( item.mbVisibleText && !mbHorz )
{
tools::Long tmp = item.maItemSize.Width();
item.maItemSize.setWidth( item.maItemSize.Height() );
item.maItemSize.setHeight( tmp );
// grow the content size by the additional available space
item.maContentSize.AdjustWidth(nGrowContentWidth );
item.maContentSize.AdjustHeight(nGrowContentHeight );
}
// keep track of max item size if ( item.maItemSize.Width() > nMaxWidth )
nMaxWidth = item.maItemSize.Width(); if ( item.maItemSize.Height() > nMaxHeight )
nMaxHeight = item.maItemSize.Height();
}
}
} else
{
nMaxWidth = nDefWidth;
nMaxHeight = nDefHeight;
if( !ImplIsFloatingMode() && GetToolboxButtonSize() != ToolBoxButtonSize::DontCare
&& ( meTextPosition == ToolBoxTextPosition::Right ) )
{ // make sure all vertical toolbars have the same width and horizontal have the same height // this depends on the used button sizes // as this is used for alignment of multiple toolbars // it is only required for docked toolbars
// do we have to recalc the sizes ? if ( (nMaxWidth != mnMaxItemWidth) || (nMaxHeight != mnMaxItemHeight) )
{
mnMaxItemWidth = nMaxWidth;
mnMaxItemHeight = nMaxHeight;
// when docked the menubutton will be in the first line if( IsMenuEnabled() && !ImplIsFloatingMode() )
nMenuWidth = mpData->maMenubuttonItem.maItemSize.Width();
// we need to know which item is the last visible one to be able to add // the menu width in case we are unable to show all the items
ImplToolItems::iterator it, lastVisible; for ( it = mpData->m_aItems.begin(); it != mpData->m_aItems.end(); ++it )
{ if ( it->mbVisible )
lastVisible = it;
}
it = mpData->m_aItems.begin(); while ( it != mpData->m_aItems.end() )
{
it->mbBreak = bBreak;
bBreak = false;
// in case we are able to show all the items, we do not want // to show the toolbar's menu; otherwise yes if ( ( ( it == lastVisible ) && (nLineWidth+nCurWidth > nWidthTotal) && mbScroll ) ||
( ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) && mbScroll ) )
bBreak = true;
} elseif ( it->meType == ToolBoxItemType::SEPARATOR )
{
nCurWidth = it->mnSepSize; if ( !ImplIsFloatingMode() && ( it != lastVisible ) && (nLineWidth+nCurWidth+nMenuWidth > nWidthTotal) )
bBreak = true;
} // treat breaks as separators, except when using old style toolbars (ie. no menu button) elseif ( (it->meType == ToolBoxItemType::BREAK) && !IsMenuEnabled() )
bBreak = true;
if ( bBreak )
{
nLines++;
// Add break before the entire group or take group apart? if ( (it->meType == ToolBoxItemType::BREAK) ||
(nLineStart == nGroupStart) )
{ if ( nLineWidth > nMaxLineWidth )
nMaxLineWidth = nLineWidth;
// if the break is added before the group, set it to // beginning of line and re-calculate
nLineWidth = 0;
nLineStart = nGroupStart;
it = mpData->m_aItems.begin() + nGroupStart; continue;
}
} else
{ if( ImplIsFloatingMode() || !IsMenuEnabled() ) // no group breaking when being docked single-line
{ if ( (it->meType != ToolBoxItemType::BUTTON) || bWindow )
{ // found separator or break
nLastGroupLineWidth = nLineWidth;
nGroupStart = it - mpData->m_aItems.begin(); if ( !bWindow )
nGroupStart++;
}
}
}
nLineWidth += nCurWidth;
}
++it;
}
if ( pMaxLineWidth )
{ if ( nLineWidth > nMaxLineWidth )
nMaxLineWidth = nLineWidth;
if( ImplIsFloatingMode() && !ImplIsInPopupMode() )
{ // leave enough space to display buttons in the decoration
tools::Long aMinWidth = 2 * GetSettings().GetStyleSettings().GetFloatTitleHeight(); if( nMaxLineWidth < aMinWidth )
nMaxLineWidth = aMinWidth;
}
*pMaxLineWidth = nMaxLineWidth;
}
// calc number of floating lines for current window height
ImplToolItems::size_type nFloatLinesHeight = ImplCalcLines( mnDY ); // calc window size according to this number
aSize1 = ImplCalcFloatSize( nFloatLinesHeight );
aSz.setHeight( nBorderY + nLineHeight * nLines ); // line space when more than one line if ( mbLineSpacing )
aSz.AdjustHeight((nLines-1)*TB_LINESPACING );
aSz.setWidth( nBorderX + maxX );
// avoid clipping of any items if( aSz.Width() < aMinimalFloatSize.Width() )
aSize2 = ImplCalcFloatSize( nLines ); else
aSize2 = aSz;
if( aCurrentSize == aSize2 ) return aSize2;
// set the size with the smallest delta as the current size
tools::Long dx1 = std::abs( mnDX - aSize1.Width() );
tools::Long dy1 = std::abs( mnDY - aSize1.Height() );
// update drag area (where the 'grip' will be placed)
tools::Rectangle aOldDragRect; if( pWrapper )
aOldDragRect = pWrapper->GetDragArea();
ImplUpdateDragArea();
bMustFullPaint = ImplCalcItem();
// calculate new size during interactive resize or // set computed size when formatting only if ( ImplIsFloatingMode() )
{ if ( bResize )
mnFloatLines = ImplCalcLines( mnDY ); else
SetOutputSizePixel( ImplGetOptimalFloatingSize() );
}
// Horizontal if ( mbHorz )
{
tools::Long nBottom; // nLineSize: height of a single line, will fit highest item
nLineSize = mnMaxItemHeight;
if ( mnWinHeight > mnMaxItemHeight )
nLineSize = mnWinHeight;
if ( mbScroll )
{
nMax = mnDX;
mnVisLines = ImplCalcLines( mnDY );
} else
{ // layout over all lines
mnVisLines = mnLines;
nMax = TB_MAXNOSCROLL;
}
// adjust linesize if docked in single-line mode (i.e. when using a clipped item menu) // we have to center all items in the window height if( IsMenuEnabled() && !ImplIsFloatingMode() )
{
tools::Long nWinHeight = mnDY - nTop - nBottom; if( nWinHeight > nLineSize )
nLineSize = nWinHeight;
}
} else
{
tools::Long nRight;
nLineSize = mnMaxItemWidth;
// adjust linesize if docked in single-line mode (i.e. when using a clipped item menu) // we have to center all items in the window height if( !ImplIsFloatingMode() && IsMenuEnabled() )
{
tools::Long nWinWidth = mnDX - nLeft - nRight; if( nWinWidth > nLineSize )
nLineSize = nWinWidth;
}
}
// no calculation if the window has no size (nMax=0) // non scrolling toolboxes must be computed though if ( (nMax <= 0) && mbScroll )
{
mnVisLines = 1;
mnCurLine = 1;
mnCurLines = 1;
// save old scroll rectangles and reset them
tools::Rectangle aOldLowerRect = maLowerRect;
tools::Rectangle aOldUpperRect = maUpperRect;
tools::Rectangle aOldMenubuttonRect = mpData->maMenubuttonItem.maRect;
maUpperRect = aEmptyRect;
maLowerRect = aEmptyRect;
mpData->maMenubuttonItem.maRect = aEmptyRect;
// do we have any toolbox items at all ? if ( !mpData->m_aItems.empty() || IsMenuEnabled() )
{
lcl_hideDoubleSeparators( mpData->m_aItems );
// compute line breaks and visible lines give the current window width (nMax) // the break indicators will be stored within each item (it->mbBreak)
mnCurLines = ImplCalcBreaks( nMax, nullptr, mbHorz );
// check for scrollbar buttons or dropdown menu // (if a menu is enabled, this will be used to store clipped // items and no scroll buttons will appear) if ( (!ImplIsFloatingMode() && (mnCurLines > mnVisLines) && mbScroll ) ||
IsMenuEnabled() )
{ // compute linebreaks again, incorporating scrollbar buttons if( !IsMenuEnabled() )
{
nMax -= TB_SPIN_SIZE+TB_SPIN_OFFSET;
mnCurLines = ImplCalcBreaks( nMax, nullptr, mbHorz );
}
// check for line break and advance nX/nY accordingly if ( item.mbBreak )
{
nFormatLine++;
// increment starting with the second line if ( nFormatLine > mnCurLine )
{ if ( mbHorz )
{
nX = nLeft; if ( mbLineSpacing )
nY += nLineSize+TB_LINESPACING; else
nY += nLineSize;
} else
{
nY = nTop; if ( mbLineSpacing )
nX += nLineSize+TB_LINESPACING; else
nX += nLineSize;
}
}
}
if ( !item.mbVisible || (nFormatLine < mnCurLine) ||
(nFormatLine > mnCurLine+mnVisLines-1) ) // item is not visible
item.maCalcRect = aEmptyRect; else
{ // 1. determine current item width/height // take window size and orientation into account, because this affects the size of item windows
// In special mode Locked first item's vertical position remains unchanged. Consecutive items vertical // positions are centered around first item's vertical position. If an item's height exceeds available // space, item's vertical position remains unchanged too.
// position window items into calculated item rect if ( item.mpWindow )
{ if ( item.mbShowWindow )
{
Point aPos( item.maCalcRect.Left(), item.maCalcRect.Top() );
assert( item.maCalcRect.Top() >= 0 );
item.mpWindow->SetPosPixel( aPos );
item.mpWindow->Show();
} else
item.mpWindow->Hide();
}
} // end of loop over all items
mbIsArranged = true;
} else // we have no toolbox items
mnCurLines = 1;
if( IsMenuEnabled() && ImplIsFloatingMode() && !ImplHasExternalMenubutton() && !bIsInPopupMode )
{ // custom menu will be the last button in floating mode
ImplToolItem &rIt = mpData->maMenubuttonItem;
mpData->mbDropDownByKeyboard = false;
mpData->maDropdownClickHdl.Call( this );
// do not reset data if the dropdown handler opened a floating window // see ImplFloatControl() if( !mpFloatWin )
{ // no floater was opened
Deactivate();
InvalidateItem(mnCurPos);
void ToolBox::ImplDrawButton(vcl::RenderContext& rRenderContext, const tools::Rectangle &rRect, sal_uInt16 highlight, bool bChecked, bool bEnabled, bool bIsWindow )
{ // draws toolbar button background either native or using a coloured selection // if bIsWindow is true, the corresponding item is a control and only a selection border will be drawn
// no gradient background for items that have a popup open bool bHasOpenPopup = mpFloatWin && (mnDownItemId==pItem->mnId);
bool bHighContrastWhite = false; // check the face color as highcontrast indicator // because the toolbox itself might have a gradient if (rStyleSettings.GetFaceColor() == COL_WHITE)
bHighContrastWhite = true;
// determine what has to be drawn on the button: image, text or both bool bImage; bool bText;
ButtonType tmpButtonType = determineButtonType( pItem, meButtonType ); // default to toolbox setting
pItem->DetermineButtonDrawStyle( tmpButtonType, bImage, bText );
// if focus is still in this toolbox, then the floater was opened by keyboard // draw current item with highlight and keep old state bool bWasKeyboardActivate = mpData->mbDropDownByKeyboard;
if ( mnCurPos != ITEM_NOTFOUND )
InvalidateItem(mnCurPos);
Deactivate();
if ( mbDrag )
mbDrag = false; else
{ if ( mnCurPos == ITEM_NOTFOUND ) returntrue;
}
// has mouse been released on top of item? if( mnCurPos < mpData->m_aItems.size() )
{
ImplToolItem* pItem = &mpData->m_aItems[mnCurPos]; if ( pItem->maRect.Contains( rMEvt.GetPosPixel() ) )
{
mnCurItemId = pItem->mnId; if ( !bCancel )
{ // execute AutoCheck if required if ( pItem->mnBits & ToolBoxItemBits::AUTOCHECK )
{ if ( pItem->mnBits & ToolBoxItemBits::RADIOCHECK )
{ if ( pItem->meState != TRISTATE_TRUE )
SetItemState( pItem->mnId, TRISTATE_TRUE );
} else
{ if ( pItem->meState != TRISTATE_TRUE )
pItem->meState = TRISTATE_TRUE; else
pItem->meState = TRISTATE_FALSE;
}
}
// do not call Select when Repeat is active, as in this // case that was triggered already in MouseButtonDown if ( !(pItem->mnBits & ToolBoxItemBits::REPEAT) )
{ // prevent from being destroyed in the select handler
VclPtr<vcl::Window> xWindow = this;
Select(); if ( xWindow->isDisposed() ) returntrue;
}
}
{
}
// Items not destroyed, in Select handler if ( mnCurItemId )
{ // Get current pos for the case that items are inserted/removed // in the toolBox
mnCurPos = GetItemPos( mnCurItemId ); if ( mnCurPos != ITEM_NOTFOUND )
{
InvalidateItem(mnCurPos);
GetOutDev()->Flush();
}
}
}
}
void ToolBox::MouseMove( const MouseEvent& rMEvt )
{ // pressing a modifier generates synthetic mouse moves // ignore it if keyboard selection is active if( HasFocus() && ( rMEvt.GetMode() & MouseEventModifiers::MODIFIERCHANGED ) ) return;
if ( ImplHandleMouseMove( rMEvt ) ) return;
Point aMousePos = rMEvt.GetPosPixel();
// only highlight when the focus is not inside a child window of a toolbox // eg, in an edit control // and do not highlight when focus is in a different toolbox bool bDrawHotSpot = true;
vcl::Window *pFocusWin = Application::GetFocusWindow();
void ToolBox::MouseButtonDown( const MouseEvent& rMEvt )
{ // only trigger toolbox for left mouse button and when // we're not in normal operation if ( rMEvt.IsLeft() && !mbDrag && (mnCurPos == ITEM_NOTFOUND) )
{ // call activate already here, as items could // be exchanged
Activate();
// update ToolBox here, such that user knows it if ( mbFormat )
{
ImplFormat();
PaintImmediately();
}
Point aMousePos = rMEvt.GetPosPixel();
ImplToolItems::size_type i = 0;
ImplToolItems::size_type nNewPos = ITEM_NOTFOUND;
// search for item that was clicked for (autoconst& item : mpData->m_aItems)
{ // is this the item? if ( item.maRect.Contains( aMousePos ) )
{ // do nothing if it is a separator or // if the item has been disabled if ( (item.meType == ToolBoxItemType::BUTTON) &&
!item.mbShowWindow )
nNewPos = i;
break;
}
i++;
}
// item found if ( nNewPos != ITEM_NOTFOUND )
{ if ( !mpData->m_aItems[nNewPos].mbEnabled )
{
Deactivate(); return;
}
// update actual data
StartTrackingFlags nTrackFlags = StartTrackingFlags::NONE;
mnCurPos = nNewPos;
mnCurItemId = mpData->m_aItems[nNewPos].mnId;
mnDownItemId = mnCurItemId;
mnMouseModifier = rMEvt.GetModifier(); if ( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::REPEAT )
nTrackFlags |= StartTrackingFlags::ButtonRepeat;
// update bDrag here, as it is evaluated in the EndSelection
mbDrag = true;
// on double-click: only call the handler, but do so before the button // is hit, as in the handler dragging // can be terminated if ( rMEvt.GetClicks() == 2 )
DoubleClick();
if ( mbDrag )
{
InvalidateItem(mnCurPos);
Highlight();
}
// was dropdown arrow pressed if( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWN )
{ if( ( (mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWNONLY) == ToolBoxItemBits::DROPDOWNONLY)
|| mpData->m_aItems[nNewPos].GetDropDownRect( mbHorz ).Contains( aMousePos ))
{ // dropdownonly always triggers the dropdown handler, over the whole button area
// the drop down arrow should not trigger the item action
mpData->mbDropDownByKeyboard = false;
mpData->maDropdownClickHdl.Call( this );
// do not reset data if the dropdown handler opened a floating window // see ImplFloatControl() if( !mpFloatWin )
{ // no floater was opened
Deactivate();
InvalidateItem(mnCurPos);
ImplToolItems::size_type nCount = mpData->m_aItems.size(); for( ImplToolItems::size_type i = 0; i < nCount; i++ )
{
ImplToolItem* pItem = &mpData->m_aItems[i];
// only draw when the rectangle is in the draw rectangle if ( !pItem->maRect.IsEmpty() && rPaintRect.Overlaps( pItem->maRect ) )
{
sal_uInt16 nHighlight = 0; if ( i == mnCurPos )
nHighlight = 1; elseif ( i == nHighPos )
nHighlight = 2;
ImplDrawItem(rRenderContext, i, nHighlight);
}
}
ImplShowFocus();
}
void ToolBox::Resize()
{
Size aSize = GetOutputSizePixel(); // #i31422# some WindowManagers send (0,0) sizes when // switching virtual desktops - ignore this and avoid reformatting if( !aSize.Width() && !aSize.Height() ) return;
// invalidate everything to have gradient backgrounds properly drawn
Invalidate();
// If we have any expandable entries, then force a reformat first using // their optimal sizes, then share out the excess space evenly across those // expandables and reformat again
std::vector<size_t> aExpandables; for (size_t i = 0; i < mpData->m_aItems.size(); ++i)
{ if (mpData->m_aItems[i].mbExpand)
{
vcl::Window *pWindow = mpData->m_aItems[i].mpWindow;
SAL_INFO_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment"); if (!pWindow) continue;
Size aWinSize(pWindow->GetSizePixel());
Size aPrefSize(pWindow->get_preferred_size());
aWinSize.setWidth( aPrefSize.Width() );
pWindow->SetSizePixel(aWinSize);
aExpandables.push_back(i);
}
}
// re-format or re-draw if ( mbScroll || !aExpandables.empty() )
{ if ( !mbFormat || !aExpandables.empty() )
{
mbFormat = true; if( IsReallyVisible() || !aExpandables.empty() )
{
ImplFormat(true);
if (!aExpandables.empty())
{ //Get how big the optimal size is
tools::Rectangle aBounds; for (const ImplToolItem & rItem : mpData->m_aItems)
{
aBounds.Union( rItem.maRect );
}
auto nOptimalWidth = aBounds.GetWidth(); auto nDiff = aSize.Width() - nOptimalWidth;
decltype(nDiff) nExpandablesSize = aExpandables.size();
nDiff /= nExpandablesSize;
//share out the diff from optimal to real across //expandable entries for (size_t nIndex : aExpandables)
{
vcl::Window *pWindow = mpData->m_aItems[nIndex].mpWindow;
Size aWinSize(pWindow->GetSizePixel());
Size aPrefSize(pWindow->get_preferred_size());
aWinSize.setWidth( aPrefSize.Width() + nDiff );
pWindow->SetSizePixel(aWinSize);
}
//now reformat with final sizes
mbFormat = true;
ImplFormat(true);
}
}
}
}
// redraw border if ( !(mnWinStyle & WB_BORDER) ) return;
// as otherwise, when painting we might think we have to re-draw everything if ( mbFormat && IsReallyVisible() )
Invalidate(); else
{ if ( mnRightBorder )
{ if ( nOldDX > mnDX )
Invalidate( tools::Rectangle( mnDX-mnRightBorder-1, 0, mnDX, mnDY ) ); else
Invalidate( tools::Rectangle( nOldDX-mnRightBorder-1, 0, nOldDX, nOldDY ) );
}
// get text and display it
OUString aStr = GetQuickHelpText( nItemId ); if (aStr.isEmpty())
aStr = MnemonicGenerator::EraseAllMnemonicChars( GetItemText( nItemId ) ); if ( rHEvt.GetMode() & HelpEventMode::BALLOON )
{ const OUString& rHelpStr = GetHelpText( nItemId ); if (!rHelpStr.isEmpty())
aStr = rHelpStr;
Help::ShowBalloon( this, aHelpPos, aTempRect, aStr );
} else
Help::ShowQuickHelp( this, aTempRect, aStr, QuickHelpFlags::CtrlText ); return;
}
}
DockingWindow::RequestHelp( rHEvt );
}
bool ToolBox::EventNotify( NotifyEvent& rNEvt )
{ if ( rNEvt.GetType() == NotifyEventType::KEYINPUT )
{
KeyEvent aKEvt = *rNEvt.GetKeyEvent();
vcl::KeyCode aKeyCode = aKEvt.GetKeyCode();
sal_uInt16 nKeyCode = aKeyCode.GetCode(); switch( nKeyCode )
{ case KEY_TAB:
{ // internal TAB cycling only if parent is not a dialog or if we are the only child // otherwise the dialog control will take over
vcl::Window *pParent = ImplGetParent(); bool bOldSchoolContainer =
((pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL &&
pParent->GetChildCount() != 1); bool bNoTabCycling = bOldSchoolContainer || isContainerWindow(pParent);
// set focus back to document
ImplGetFrameWindow()->GetWindow( GetWindowType::Client )->GrabFocus();
}
if( bOldHorz != mbHorz )
{ // if orientation changes, the toolbox has to be initialized again // to update the direction of the gradient
mbCalc = true;
ImplInitSettings( true, true, true );
}
bool ToolBox::Docking( const Point& rPos, tools::Rectangle& rRect )
{ // do nothing during dragging, it was calculated before if ( mbDragging ) returnfalse;
bool bFloatMode = false;
DockingWindow::Docking( rPos, rRect );
// if the mouse is outside the area, it can only become a floating window
tools::Rectangle aDockingRect( rRect ); if ( !ImplIsFloatingMode() )
{ // don't use tracking rectangle for alignment check, because it will be too large // to get a floating mode as result - switch to floating size // so the calculation only depends on the position of the rectangle, not the current // docking state of the window
ImplToolItems::size_type nTemp = 0;
aDockingRect.SetSize( ImplCalcFloatSize( nTemp ) );
// in this mode docking is never done by keyboard, so it's OK to use the mouse position
aDockingRect.SetPos( ImplGetFrameWindow()->GetPointerPosPixel() );
}
Size ToolBox::GetOptimalSize() const
{ // If we have any expandable entries, then force them to their // optimal sizes, then reset them afterwards
std::map<vcl::Window*, Size> aExpandables; for (const ImplToolItem & rItem : mpData->m_aItems)
{ if (rItem.mbExpand)
{
vcl::Window *pWindow = rItem.mpWindow;
SAL_INFO_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment"); if (!pWindow) continue;
Size aWinSize(pWindow->GetSizePixel());
aExpandables[pWindow] = aWinSize;
Size aPrefSize(pWindow->get_preferred_size());
aWinSize.setWidth( aPrefSize.Width() );
pWindow->SetSizePixel(aWinSize);
}
}
// copy until first useful item for (autoconst& item : mpData->m_aItems)
{
pToolBox->CopyItem( *this, item.mnId ); if( (item.meType == ToolBoxItemType::BUTTON) &&
item.mbVisible && !ImplIsFixedControl( &item ) ) break;
}
// add to docking manager if required to obtain a drag area // (which is accounted for in calcwindowsizepixel) if( ImplGetDockingManager()->GetDockingWindowWrapper( this ) )
ImplGetDockingManager()->AddWindow( pToolBox );
// account for menu if( IsMenuEnabled() )
pToolBox->SetMenuType( GetMenuType() );
staticbool ImplCloseLastPopup( vcl::Window const *pParent )
{ // close last popup toolbox (see also: // ImplHandleMouseFloatMode(...) in winproc.cxx )
if (ImplGetSVData()->mpWinData->mpFirstFloat)
{
FloatingWindow* pLastLevelFloat = ImplGetSVData()->mpWinData->mpFirstFloat->ImplFindLastLevelFloat(); // only close the floater if it is not our direct parent, which would kill ourself if( pLastLevelFloat && pLastLevelFloat != pParent )
{
pLastLevelFloat->EndPopupMode( FloatWinPopupEndFlags::Cancel | FloatWinPopupEndFlags::CloseAll ); returntrue;
}
} returnfalse;
}
// opens a drop down toolbox item // returns true if item was opened bool ToolBox::ImplOpenItem( vcl::KeyCode aKeyCode )
{
sal_uInt16 nCode = aKeyCode.GetCode(); bool bRet = true;
// arrow keys should work only in the opposite direction of alignment (to not break cursor travelling) if ( ((nCode == KEY_LEFT || nCode == KEY_RIGHT) && IsHorizontal())
|| ((nCode == KEY_UP || nCode == KEY_DOWN) && !IsHorizontal()) ) returnfalse;
// returns the current toolbox line of the item
ToolBox::ImplToolItems::size_type ToolBox::ImplGetItemLine( ImplToolItem const * pCurrentItem )
{
ImplToolItems::size_type nLine = 1; for (autoconst& item : mpData->m_aItems)
{ if ( item.mbBreak )
++nLine; if( &item == pCurrentItem) break;
} return nLine;
}
// returns the first displayable item in the given line
ImplToolItem* ToolBox::ImplGetFirstValidItem( ImplToolItems::size_type nLine )
{ if( !nLine || nLine > mnCurLines ) return nullptr;
nLine--;
ImplToolItems::iterator it = mpData->m_aItems.begin(); while( it != mpData->m_aItems.end() )
{ // find correct line if ( it->mbBreak )
nLine--; if( !nLine )
{ // find first useful item while( it != mpData->m_aItems.end() && ((it->meType != ToolBoxItemType::BUTTON) || /*!it->mbEnabled ||*/ !it->mbVisible || ImplIsFixedControl( &(*it) )) )
{
++it; if( it == mpData->m_aItems.end() || it->mbBreak ) return nullptr; // no valid items in this line
} return &(*it);
}
++it;
}
if ( mnHighItemId )
{
ImplHideFocus();
ImplToolItems::size_type nPos = GetItemPos( mnHighItemId );
pOldItem = ImplGetItem( mnHighItemId ); // #i89962# ImplDrawItem can cause Invalidate/Update // which will in turn ImplShowFocus again // set mnHighItemId to 0 already to prevent this hen/egg problem
mnHighItemId = ToolBoxItemId(0);
InvalidateItem(nPos);
CallEventListeners( VclEventId::ToolboxHighlightOff, reinterpret_cast< void* >( nPos ) );
}
// highlight the menu button if it is the last item if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
{
ImplChangeHighlight( nullptr );
mpData->mbMenubuttonSelected = true;
InvalidateMenuButton(); returntrue;
} else
pos = nCount-1;
}
} else
{ if( ++pos >= nCount )
{ if( bNoCycle ) returnfalse;
// highlight the menu button if it is the last item if( ImplHasClippedItems() && IsMenuEnabled() && !ImplIsFloatingMode() )
{
ImplChangeHighlight( nullptr );
mpData->mbMenubuttonSelected = true;
InvalidateMenuButton(); returntrue;
} else
pos = 0;
}
}
pToolItem = &mpData->m_aItems[pos];
if ( ImplIsValidItem( pToolItem, false ) ) break;
} while( ++i < nCount);
if( pToolItem->IsClipped() && IsMenuEnabled() )
{ // select the menu button if a clipped item would be selected
ImplChangeHighlight( nullptr );
mpData->mbMenubuttonSelected = true;
InvalidateMenuButton();
} elseif( i != nCount )
ImplChangeHighlight( pToolItem ); else returnfalse;
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.150Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-05-05)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.