/* -*- 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;
}
// add in all border offsets if ( mnWinStyle & WB_BORDER )
{
--> --------------------
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.