Kaydet (Commit) a4d1dea6 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

Unify drag handles for toolboxes

The custom shape popup toolbars used their own drawing code for
the drag handle. This was dropped in favour of the default toolbox
drag handle code.

This also drops the drag highlighting in favour of a move mouse
cursor as the drag indicator. The drag handle is currently always
drawn on the top, like a window title.

Change-Id: I08cbf715f1e240c2eb6d9a61fad2b705f9bd8014
üst 716f8f39
...@@ -223,9 +223,14 @@ public: ...@@ -223,9 +223,14 @@ public:
SAL_DLLPRIVATE void ImplDisableFlatButtons(); SAL_DLLPRIVATE void ImplDisableFlatButtons();
static SAL_DLLPRIVATE int ImplGetDragWidth( ToolBox* pThis ); static SAL_DLLPRIVATE int ImplGetDragWidth( ToolBox* pThis );
static SAL_DLLPRIVATE int ImplGetDragWidth( const vcl::RenderContext& rRenderContext,
bool bHorz );
static SAL_DLLPRIVATE void ImplUpdateDragArea( ToolBox *pThis ); static SAL_DLLPRIVATE void ImplUpdateDragArea( ToolBox *pThis );
static SAL_DLLPRIVATE void ImplCalcBorder( WindowAlign eAlign, long& rLeft, long& rTop, static SAL_DLLPRIVATE void ImplCalcBorder( WindowAlign eAlign, long& rLeft, long& rTop,
long& rRight, long& rBottom, const ToolBox *pThis ); long& rRight, long& rBottom, const ToolBox *pThis );
static SAL_DLLPRIVATE void ImplDrawGrip(vcl::RenderContext& rRenderContext,
const Rectangle &aDragArea, int nDragWidth,
WindowAlign eAlign, bool bHorz);
SAL_DLLPRIVATE void ImplDrawGrip(vcl::RenderContext& rRenderContext); SAL_DLLPRIVATE void ImplDrawGrip(vcl::RenderContext& rRenderContext);
SAL_DLLPRIVATE void ImplDrawGradientBackground(vcl::RenderContext& rRenderContext, ImplDockingWindowWrapper *pWrapper); SAL_DLLPRIVATE void ImplDrawGradientBackground(vcl::RenderContext& rRenderContext, ImplDockingWindowWrapper *pWrapper);
......
...@@ -424,29 +424,10 @@ Rectangle DockingManager::GetPosSizePixel( const vcl::Window *pWindow ) ...@@ -424,29 +424,10 @@ Rectangle DockingManager::GetPosSizePixel( const vcl::Window *pWindow )
return aRect; return aRect;
} }
// special floating window for popup mode
// main purpose: provides tear-off area for undocking
// if TEAROFF_DASHED defined a single dashed line is used
// otherwise multiple smaller lines will be painted
//#define TEAROFF_DASHED
// size of the drag area
#ifdef TEAROFF_DASHED
#define POPUP_DRAGBORDER 2
#define POPUP_DRAGGRIP 5
#else
#define POPUP_DRAGBORDER 3
#define POPUP_DRAGGRIP 5
#endif
#define POPUP_DRAGHEIGHT (POPUP_DRAGGRIP+POPUP_DRAGBORDER+POPUP_DRAGBORDER)
#define POPUP_DRAGWIDTH 20
class ImplPopupFloatWin : public FloatingWindow class ImplPopupFloatWin : public FloatingWindow
{ {
private: private:
ImplDockingWindowWrapper* mpDockingWin; ImplDockingWindowWrapper* mpDockingWin;
bool mbHighlight;
bool mbMoving; bool mbMoving;
bool mbTrackingEnabled; bool mbTrackingEnabled;
Point maDelta; Point maDelta;
...@@ -454,7 +435,8 @@ private: ...@@ -454,7 +435,8 @@ private:
void ImplSetBorder(); void ImplSetBorder();
public: public:
ImplPopupFloatWin( vcl::Window* pParent, ImplDockingWindowWrapper* pDockingWin, bool bHasGrip ); ImplPopupFloatWin( vcl::Window* pParent, ImplDockingWindowWrapper* pDockingWin,
bool bHasGrip, bool bUsePopupWin );
virtual ~ImplPopupFloatWin() override; virtual ~ImplPopupFloatWin() override;
virtual void dispose() override; virtual void dispose() override;
...@@ -467,22 +449,23 @@ public: ...@@ -467,22 +449,23 @@ public:
virtual void Resize() override; virtual void Resize() override;
Rectangle GetDragRect() const; Rectangle GetDragRect() const;
Point GetToolboxPosition() const;
void DrawGrip(vcl::RenderContext& rRenderContext); void DrawGrip(vcl::RenderContext& rRenderContext);
void DrawBorder(vcl::RenderContext& rRenderContext); void DrawBorder(vcl::RenderContext& rRenderContext);
bool hasGrip() const { return mbHasGrip; } bool hasGrip() const { return mbHasGrip; }
}; };
ImplPopupFloatWin::ImplPopupFloatWin( vcl::Window* pParent, ImplDockingWindowWrapper* pDockingWin, bool bHasGrip ) : ImplPopupFloatWin::ImplPopupFloatWin( vcl::Window* pParent, ImplDockingWindowWrapper* pDockingWin,
FloatingWindow( pParent, WB_NOBORDER | WB_SYSTEMWINDOW | WB_NOSHADOW) bool bHasGrip, bool bUsePopupWin ) :
FloatingWindow( pParent, bUsePopupWin ? WB_STDPOPUP : WB_NOBORDER | WB_SYSTEMWINDOW | WB_NOSHADOW)
{ {
mpWindowImpl->mbToolbarFloatingWindow = true; // indicate window type, required for accessibility mpWindowImpl->mbToolbarFloatingWindow = true; // indicate window type, required for accessibility
// which should not see this window as a toplevel window // which should not see this window as a toplevel window
mpDockingWin = pDockingWin; mpDockingWin = pDockingWin;
mbHighlight = false;
mbMoving = false; mbMoving = false;
mbTrackingEnabled = false; mbTrackingEnabled = false;
mbHasGrip = bHasGrip; mbHasGrip = !bUsePopupWin && bHasGrip;
ImplSetBorder(); ImplSetBorder();
} }
...@@ -517,7 +500,7 @@ void ImplPopupFloatWin::ImplSetBorder() ...@@ -517,7 +500,7 @@ void ImplPopupFloatWin::ImplSetBorder()
// be used to set the proper window size // be used to set the proper window size
mpWindowImpl->mnTopBorder = 1; mpWindowImpl->mnTopBorder = 1;
if( hasGrip() ) if( hasGrip() )
mpWindowImpl->mnTopBorder += POPUP_DRAGHEIGHT+2; mpWindowImpl->mnTopBorder += 2 + ToolBox::ImplGetDragWidth( *this, false );
mpWindowImpl->mnBottomBorder = 1; mpWindowImpl->mnBottomBorder = 1;
mpWindowImpl->mnLeftBorder = 1; mpWindowImpl->mnLeftBorder = 1;
mpWindowImpl->mnRightBorder = 1; mpWindowImpl->mnRightBorder = 1;
...@@ -533,9 +516,14 @@ Rectangle ImplPopupFloatWin::GetDragRect() const ...@@ -533,9 +516,14 @@ Rectangle ImplPopupFloatWin::GetDragRect() const
{ {
if( !hasGrip() ) if( !hasGrip() )
return Rectangle(); return Rectangle();
return Rectangle( 1, 1, GetOutputSizePixel().Width() - 1,
2 + ToolBox::ImplGetDragWidth( *this, false ) );
}
return Rectangle( 1, GetOutputSizePixel().Height() - 3 - POPUP_DRAGHEIGHT, Point ImplPopupFloatWin::GetToolboxPosition() const
GetOutputSizePixel().Width() - 1, GetOutputSizePixel().Height() - 1 ); {
// return inner position where a toolbox could be placed
return Point( 1, 1 + GetDragRect().getHeight() ); // grip + border
} }
void ImplPopupFloatWin::DrawBorder(vcl::RenderContext& rRenderContext) void ImplPopupFloatWin::DrawBorder(vcl::RenderContext& rRenderContext)
...@@ -570,76 +558,10 @@ void ImplPopupFloatWin::DrawGrip(vcl::RenderContext& rRenderContext) ...@@ -570,76 +558,10 @@ void ImplPopupFloatWin::DrawGrip(vcl::RenderContext& rRenderContext)
bool bFillcolor = rRenderContext.IsFillColor(); bool bFillcolor = rRenderContext.IsFillColor();
Color aFillcolor = rRenderContext.GetFillColor(); Color aFillcolor = rRenderContext.GetFillColor();
// draw background
Rectangle aRect(GetDragRect());
aRect.Top() += POPUP_DRAGBORDER;
aRect.Bottom() -= POPUP_DRAGBORDER;
aRect.Left() += 3;
aRect.Right() -= 3;
if (mbHighlight)
{
rRenderContext.Erase(aRect);
vcl::RenderTools::DrawSelectionBackground(rRenderContext, *this, aRect, 2, false, true, false);
}
else
{
rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetFaceColor());
rRenderContext.SetLineColor();
rRenderContext.DrawRect(aRect);
}
if (!ToolBox::AlwaysLocked()) // no grip if toolboxes are locked if (!ToolBox::AlwaysLocked()) // no grip if toolboxes are locked
{ {
#ifdef TEAROFF_DASHED ToolBox::ImplDrawGrip(rRenderContext, GetDragRect(),
// draw single dashed line ToolBox::ImplGetDragWidth( *this, false ), WindowAlign::Left, false );
LineInfo aLineInfo(LineStyle::Dash);
aLineInfo.SetDistance(4);
aLineInfo.SetDashLen(12);
aLineInfo.SetDashCount(1);
aRect.Left() += 2;
aRect.Right()-= 2;
aRect.Top() += 2;
aRect.Bottom() = aRect.Top();
rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetDarkShadowColor());
rRenderContext.DrawLine(aRect.TopLeft(), aRect.TopRight(), aLineInfo);
if (!mbHighlight)
{
++aRect.Top();
++aRect.Bottom();
rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetLightColor());
rRenderContext.DrawLine(aRect.TopLeft(), aRect.TopRight(), aLineInfo);
}
#else
// draw several grip lines
rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetShadowColor());
aRect.Top()++;
aRect.Bottom() = aRect.Top();
int width = POPUP_DRAGWIDTH;
while(width >= aRect.getWidth())
{
width -= 4;
}
if (width <= 0)
width = aRect.getWidth();
//aRect.nLeft = aRect.nLeft + (aRect.getWidth() - width) / 2;
aRect.Left() = (aRect.Left() + aRect.Right() - width) / 2;
aRect.Right() = aRect.Left() + width;
int i = 0;
while (i < POPUP_DRAGGRIP)
{
rRenderContext.DrawRect(aRect);
aRect.Top() += 2;
aRect.Bottom() += 2;
i += 2;
}
#endif
} }
if (bLinecolor) if (bLinecolor)
...@@ -674,15 +596,15 @@ void ImplPopupFloatWin::MouseMove( const MouseEvent& rMEvt ) ...@@ -674,15 +596,15 @@ void ImplPopupFloatWin::MouseMove( const MouseEvent& rMEvt )
StartTracking( StartTrackingFlags::NoKeyCancel ); StartTracking( StartTrackingFlags::NoKeyCancel );
return; return;
} }
if( !mbHighlight && GetDragRect().IsInside( aMousePos ) ) if( GetDragRect().IsInside( aMousePos ) )
{ {
mbHighlight = true; if( GetPointer().GetStyle() != PointerStyle::Move )
Invalidate(); SetPointer( Pointer( PointerStyle::Move ) );
} }
if (mbHighlight && ( rMEvt.IsLeaveWindow() || !GetDragRect().IsInside( aMousePos ) ) ) if( rMEvt.IsLeaveWindow() || !GetDragRect().IsInside( aMousePos ) )
{ {
mbHighlight = false; if( GetPointer().GetStyle() != PointerStyle::Arrow )
Invalidate(); SetPointer( Pointer( PointerStyle::Arrow ) );
} }
} }
} }
...@@ -1053,12 +975,8 @@ void ImplDockingWindowWrapper::StartPopupMode( ToolBox *pParentToolBox, FloatWin ...@@ -1053,12 +975,8 @@ void ImplDockingWindowWrapper::StartPopupMode( ToolBox *pParentToolBox, FloatWin
bool bIsToolBox = GetWindow()->GetType() == WINDOW_TOOLBOX; bool bIsToolBox = GetWindow()->GetType() == WINDOW_TOOLBOX;
// the new parent for popup mode // the new parent for popup mode
VclPtr<FloatingWindow> pWin; VclPtrInstance<ImplPopupFloatWin> pWin( mpParent, this, bAllowTearOff,
if ( bAllowTearOff && !bIsToolBox ) bAllowTearOff && !bIsToolBox );
pWin = VclPtr<FloatingWindow>::Create( mpParent, WB_STDPOPUP );
else
pWin = VclPtr<ImplPopupFloatWin>::Create( mpParent, this, bAllowTearOff );
pWin->SetPopupModeEndHdl( LINK( this, ImplDockingWindowWrapper, PopupModeEnd ) ); pWin->SetPopupModeEndHdl( LINK( this, ImplDockingWindowWrapper, PopupModeEnd ) );
pWin->SetText( GetWindow()->GetText() ); pWin->SetText( GetWindow()->GetText() );
...@@ -1070,8 +988,8 @@ void ImplDockingWindowWrapper::StartPopupMode( ToolBox *pParentToolBox, FloatWin ...@@ -1070,8 +988,8 @@ void ImplDockingWindowWrapper::StartPopupMode( ToolBox *pParentToolBox, FloatWin
GetWindow()->mpWindowImpl->mnRightBorder = 0; GetWindow()->mpWindowImpl->mnRightBorder = 0;
GetWindow()->mpWindowImpl->mnBottomBorder = 0; GetWindow()->mpWindowImpl->mnBottomBorder = 0;
// position toolbox above DragRect // position toolbox below the drag grip
GetWindow()->SetPosPixel( Point( 1, 1 ) ); GetWindow()->SetPosPixel( pWin->GetToolboxPosition() );
// reparent borderwindow and window // reparent borderwindow and window
if ( mpOldBorderWin ) if ( mpOldBorderWin )
......
...@@ -148,30 +148,36 @@ static ImplTBDragMgr* ImplGetTBDragMgr() ...@@ -148,30 +148,36 @@ static ImplTBDragMgr* ImplGetTBDragMgr()
return pSVData->maCtrlData.mpTBDragMgr; return pSVData->maCtrlData.mpTBDragMgr;
} }
int ToolBox::ImplGetDragWidth( ToolBox* pThis ) int ToolBox::ImplGetDragWidth( const vcl::RenderContext& rRenderContext, bool bHorz )
{ {
int nWidth = TB_DRAGWIDTH; int nWidth = TB_DRAGWIDTH;
if( pThis->IsNativeControlSupported( ControlType::Toolbar, ControlPart::Entire ) ) if( rRenderContext.IsNativeControlSupported( ControlType::Toolbar, ControlPart::Entire ) )
{ {
ImplControlValue aControlValue; ImplControlValue aControlValue;
Point aPoint; Point aPoint;
Rectangle aContent, aBound; Rectangle aContent, aBound;
Rectangle aArea( aPoint, pThis->GetOutputSizePixel() ); Rectangle aArea( aPoint, rRenderContext.GetOutputSizePixel() );
if ( pThis->GetNativeControlRegion(ControlType::Toolbar, pThis->mbHorz ? ControlPart::ThumbVert : ControlPart::ThumbHorz, if ( rRenderContext.GetNativeControlRegion(ControlType::Toolbar,
bHorz ? ControlPart::ThumbVert : ControlPart::ThumbHorz,
aArea, ControlState::NONE, aControlValue, OUString(), aBound, aContent) ) aArea, ControlState::NONE, aControlValue, OUString(), aBound, aContent) )
{ {
nWidth = pThis->mbHorz ? aContent.GetWidth() : aContent.GetHeight(); nWidth = bHorz ? aContent.GetWidth() : aContent.GetHeight();
} }
} }
// increase the hit area of the drag handle according to DPI scale factor // increase the hit area of the drag handle according to DPI scale factor
nWidth *= pThis->GetDPIScaleFactor(); nWidth *= rRenderContext.GetDPIScaleFactor();
return nWidth; return nWidth;
} }
int ToolBox::ImplGetDragWidth( ToolBox* pThis )
{
return ToolBox::ImplGetDragWidth( *pThis, pThis->mbHorz );
}
ButtonType determineButtonType( ImplToolItem* pItem, ButtonType defaultType ) ButtonType determineButtonType( ImplToolItem* pItem, ButtonType defaultType )
{ {
ButtonType tmpButtonType = defaultType; ButtonType tmpButtonType = defaultType;
...@@ -263,65 +269,72 @@ static void ImplCheckUpdate(ToolBox* pThis) ...@@ -263,65 +269,72 @@ static void ImplCheckUpdate(ToolBox* pThis)
pThis->Update(); pThis->Update();
} }
void ToolBox::ImplDrawGrip(vcl::RenderContext& rRenderContext) void ToolBox::ImplDrawGrip(vcl::RenderContext& rRenderContext,
const Rectangle &aDragArea, int nDragWidth, WindowAlign eAlign, bool bHorz)
{ {
ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper(this); bool bNativeOk = false;
if( pWrapper && !pWrapper->GetDragArea().IsEmpty() ) const ControlPart ePart = bHorz ? ControlPart::ThumbVert : ControlPart::ThumbHorz;
const Size aSz( rRenderContext.GetOutputSizePixel() );
if (rRenderContext.IsNativeControlSupported(ControlType::Toolbar, ePart))
{ {
// execute pending paint requests ToolbarValue aToolbarValue;
ImplCheckUpdate(this); aToolbarValue.maGripRect = aDragArea;
bool bNativeOk = false; Point aPt;
if (rRenderContext.IsNativeControlSupported(ControlType::Toolbar, mbHorz ? ControlPart::ThumbHorz : ControlPart::ThumbVert)) Rectangle aCtrlRegion(aPt, aSz);
{ ControlState nState = ControlState::ENABLED;
ToolbarValue aToolbarValue;
aToolbarValue.maGripRect = pWrapper->GetDragArea();
Point aPt; bNativeOk = rRenderContext.DrawNativeControl( ControlType::Toolbar, ePart,
Rectangle aCtrlRegion(aPt, GetOutputSizePixel()); aCtrlRegion, nState, aToolbarValue, OUString() );
ControlState nState = ControlState::ENABLED; }
bNativeOk = rRenderContext.DrawNativeControl( ControlType::Toolbar, mbHorz ? ControlPart::ThumbVert : ControlPart::ThumbHorz,
aCtrlRegion, nState, aToolbarValue, OUString() );
}
if( bNativeOk ) if( bNativeOk )
return; return;
const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings(); const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
rRenderContext.SetLineColor(rStyleSettings.GetShadowColor()); rRenderContext.SetLineColor(rStyleSettings.GetShadowColor());
rRenderContext.SetFillColor(rStyleSettings.GetShadowColor()); rRenderContext.SetFillColor(rStyleSettings.GetShadowColor());
Size aSz(GetOutputSizePixel()); float fScaleFactor = rRenderContext.GetDPIScaleFactor();
float fScaleFactor = rRenderContext.GetDPIScaleFactor();
if (meAlign == WindowAlign::Top || meAlign == WindowAlign::Bottom) if (eAlign == WindowAlign::Top || eAlign == WindowAlign::Bottom)
{
int height = (int) (0.6 * aSz.Height() + 0.5);
int i = (aSz.Height() - height) / 2;
height += i;
while (i <= height)
{ {
int height = (int) (0.6 * aSz.Height() + 0.5); int x = nDragWidth / 2;
int i = (aSz.Height() - height) / 2; rRenderContext.DrawEllipse(Rectangle(Point(x, i), Size(2 * fScaleFactor, 2 * fScaleFactor)));
height += i; i += 4 * fScaleFactor;
while (i <= height)
{
int x = ImplGetDragWidth(this) / 2;
rRenderContext.DrawEllipse(Rectangle(Point(x, i), Size(2 * fScaleFactor, 2 * fScaleFactor)));
i += 4 * fScaleFactor;
}
} }
else }
else
{
int width = (int) (0.6 * aSz.Width() + 0.5);
int i = (aSz.Width() - width) / 2;
width += i;
while (i <= width)
{ {
int width = (int) (0.6 * aSz.Width() + 0.5); int y = nDragWidth / 2;
int i = (aSz.Width() - width) / 2; rRenderContext.DrawEllipse(Rectangle(Point(i, y), Size(2 * fScaleFactor, 2 * fScaleFactor)));
width += i; i += 4 * fScaleFactor;
while (i <= width)
{
int y = ImplGetDragWidth(this) / 2;
rRenderContext.DrawEllipse(Rectangle(Point(i, y), Size(2 * fScaleFactor, 2 * fScaleFactor)));
i += 4 * fScaleFactor;
}
} }
} }
} }
void ToolBox::ImplDrawGrip(vcl::RenderContext& rRenderContext)
{
ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper(this);
if( pWrapper && !pWrapper->GetDragArea().IsEmpty() )
{
// execute pending paint requests
ImplCheckUpdate(this);
ImplDrawGrip( rRenderContext, pWrapper->GetDragArea(),
ImplGetDragWidth(this), meAlign, mbHorz );
}
}
void ToolBox::ImplDrawGradientBackground(vcl::RenderContext& rRenderContext, ImplDockingWindowWrapper*) void ToolBox::ImplDrawGradientBackground(vcl::RenderContext& rRenderContext, ImplDockingWindowWrapper*)
{ {
// draw a nice gradient // draw a nice gradient
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment