1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "toolpaneldrawer.hxx"
22 #include "toolpaneldrawerpeer.hxx"
23 #include "svtools/svtresid.hxx"
24 #include "svtools/svtools.hrc"
26 #include <com/sun/star/accessibility/AccessibleRole.hpp>
28 #include <vcl/lineinfo.hxx>
29 #include <vcl/image.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/vclevent.hxx>
33 //......................................................................................................................
36 //......................................................................................................................
38 using ::com::sun::star::uno::Reference
;
39 using ::com::sun::star::awt::XWindowPeer
;
40 namespace AccessibleRole
= ::com::sun::star::accessibility::AccessibleRole
;
42 static const int s_nIndentationWidth
= 16;
44 //==================================================================================================================
45 //= DrawerVisualization
46 //==================================================================================================================
47 //------------------------------------------------------------------------------------------------------------------
48 DrawerVisualization::DrawerVisualization( ToolPanelDrawer
& i_rParent
)
50 ,m_rDrawer( i_rParent
)
52 SetMouseTransparent( sal_True
);
54 SetAccessibleRole( AccessibleRole::LABEL
);
57 //------------------------------------------------------------------------------------------------------------------
58 DrawerVisualization::~DrawerVisualization()
62 //------------------------------------------------------------------------------------------------------------------
63 void DrawerVisualization::Paint( const Rectangle
& i_rBoundingBox
)
65 Window::Paint( i_rBoundingBox
);
69 //==================================================================================================================
71 //==================================================================================================================
72 //------------------------------------------------------------------------------------------------------------------
73 ToolPanelDrawer::ToolPanelDrawer( Window
& i_rParent
, const OUString
& i_rTitle
)
74 :Window( &i_rParent
, WB_TABSTOP
)
75 ,m_pPaintDevice( new VirtualDevice( *this ) )
76 ,m_aVisualization( *this )
80 EnableMapMode( sal_False
);
81 SetBackground( Wallpaper() );
82 SetPointer( POINTER_REFHAND
);
84 SetAccessibleRole( AccessibleRole::LIST_ITEM
);
87 SetAccessibleName( i_rTitle
);
88 SetAccessibleDescription( i_rTitle
);
90 m_aVisualization
.SetAccessibleName( i_rTitle
);
91 m_aVisualization
.SetAccessibleDescription( i_rTitle
);
94 //------------------------------------------------------------------------------------------------------------------
95 ToolPanelDrawer::~ToolPanelDrawer()
99 //------------------------------------------------------------------------------------------------------------------
100 long ToolPanelDrawer::GetPreferredHeightPixel() const
102 Rectangle
aTitleBarBox( impl_calcTitleBarBox( impl_calcTextBoundingBox() ) );
103 return aTitleBarBox
.GetHeight();
106 //------------------------------------------------------------------------------------------------------------------
107 void ToolPanelDrawer::Paint()
109 m_pPaintDevice
->SetMapMode( GetMapMode() );
110 m_pPaintDevice
->SetOutputSize( GetOutputSizePixel() );
111 m_pPaintDevice
->SetSettings( GetSettings() );
112 m_pPaintDevice
->SetDrawMode( GetDrawMode() );
114 const Rectangle
aTextBox( impl_calcTextBoundingBox() );
115 impl_paintBackground( impl_calcTitleBarBox( aTextBox
) );
117 Rectangle
aFocusBox( impl_paintExpansionIndicator( aTextBox
) );
119 m_pPaintDevice
->DrawText( aTextBox
, GetText(), impl_getTextStyle() );
121 aFocusBox
.Union( aTextBox
);
122 aFocusBox
.Left() += 2;
123 impl_paintFocusIndicator( aFocusBox
);
125 m_aVisualization
.DrawOutDev(
126 Point(), GetOutputSizePixel(),
127 Point(), GetOutputSizePixel(),
132 //------------------------------------------------------------------------------------------------------------------
133 Rectangle
ToolPanelDrawer::impl_paintExpansionIndicator( const Rectangle
& i_rTextBox
)
135 Rectangle aExpansionIndicatorArea
;
137 Image
aImage( impl_getExpansionIndicator() );
138 const int nHeight( aImage
.GetSizePixel().Height() );
143 i_rTextBox
.Top() + ( GetTextHeight() - nHeight
) / 2
145 m_pPaintDevice
->DrawImage( aPosition
, aImage
);
147 aExpansionIndicatorArea
= Rectangle( aPosition
, aImage
.GetSizePixel() );
150 return aExpansionIndicatorArea
;
154 Image
ToolPanelDrawer::impl_getExpansionIndicator() const
156 sal_uInt16 nResourceId
= 0;
158 nResourceId
= IMG_TRIANGLE_DOWN
;
160 nResourceId
= IMG_TRIANGLE_RIGHT
;
161 return Image( SvtResId( nResourceId
) );
165 sal_uInt16
ToolPanelDrawer::impl_getTextStyle() const
167 const sal_uInt16 nBasicStyle
= TEXT_DRAW_LEFT
169 | TEXT_DRAW_WORDBREAK
;
174 return nBasicStyle
| TEXT_DRAW_DISABLE
;
177 //------------------------------------------------------------------------------------------------------------------
178 void ToolPanelDrawer::impl_paintBackground( const Rectangle
& i_rTitleBarBox
)
180 m_pPaintDevice
->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
181 m_pPaintDevice
->DrawRect( i_rTitleBarBox
);
183 m_pPaintDevice
->SetFillColor();
184 m_pPaintDevice
->SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
185 m_pPaintDevice
->DrawLine( i_rTitleBarBox
.TopLeft(), i_rTitleBarBox
.TopRight() );
186 m_pPaintDevice
->DrawLine( i_rTitleBarBox
.TopLeft(), i_rTitleBarBox
.BottomLeft() );
188 m_pPaintDevice
->SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
189 m_pPaintDevice
->DrawLine( i_rTitleBarBox
.BottomLeft(), i_rTitleBarBox
.BottomRight() );
190 m_pPaintDevice
->DrawLine( i_rTitleBarBox
.TopRight(), i_rTitleBarBox
.BottomRight() );
193 //------------------------------------------------------------------------------------------------------------------
194 void ToolPanelDrawer::impl_paintFocusIndicator( const Rectangle
& i_rTextBox
)
198 const Rectangle
aTextPixelBox( m_pPaintDevice
->LogicToPixel( i_rTextBox
) );
200 m_pPaintDevice
->EnableMapMode( sal_False
);
201 m_pPaintDevice
->SetFillColor();
203 Rectangle
aBox( i_rTextBox
);
207 m_pPaintDevice
->DrawRect( aTextPixelBox
);
209 LineInfo
aDottedStyle( LINE_DASH
);
210 aDottedStyle
.SetDashCount( 0 );
211 aDottedStyle
.SetDotCount( 1 );
212 aDottedStyle
.SetDotLen( 1 );
213 aDottedStyle
.SetDistance( 1 );
215 m_pPaintDevice
->SetLineColor( COL_BLACK
);
216 m_pPaintDevice
->DrawPolyLine( Polygon( aTextPixelBox
), aDottedStyle
);
217 m_pPaintDevice
->EnableMapMode( sal_False
);
223 //------------------------------------------------------------------------------------------------------------------
224 void ToolPanelDrawer::GetFocus()
230 //------------------------------------------------------------------------------------------------------------------
231 void ToolPanelDrawer::LoseFocus()
237 //------------------------------------------------------------------------------------------------------------------
238 void ToolPanelDrawer::Resize()
241 m_aVisualization
.SetPosSizePixel( Point(), GetOutputSizePixel() );
244 //------------------------------------------------------------------------------------------------------------------
245 void ToolPanelDrawer::MouseButtonDown( const MouseEvent
& i_rMouseEvent
)
247 // consume this event, and do not forward to the base class - it would sent a NotifyEvent, which in turn, when
248 // we live in a DockingWindow, would start undocking
252 //------------------------------------------------------------------------------------------------------------------
253 void ToolPanelDrawer::DataChanged( const DataChangedEvent
& i_rEvent
)
255 Window::DataChanged( i_rEvent
);
257 switch ( i_rEvent
.GetType() )
259 case DATACHANGED_SETTINGS
:
260 if ( ( i_rEvent
.GetFlags() & SETTINGS_STYLE
) == 0 )
262 SetSettings( Application::GetSettings() );
263 m_pPaintDevice
.reset( new VirtualDevice( *this ) );
267 case DATACHANGED_FONTS
:
268 case DATACHANGED_FONTSUBSTITUTION
:
270 const StyleSettings
& rStyleSettings( GetSettings().GetStyleSettings() );
273 Font aFont
= rStyleSettings
.GetAppFont();
274 if ( IsControlFont() )
275 aFont
.Merge( GetControlFont() );
276 SetZoomedPointFont( aFont
);
280 if ( IsControlForeground() )
281 aColor
= GetControlForeground();
283 aColor
= rStyleSettings
.GetButtonTextColor();
284 SetTextColor( aColor
);
293 //------------------------------------------------------------------------------------------------------------------
294 Reference
< XWindowPeer
> ToolPanelDrawer::GetComponentInterface( sal_Bool i_bCreate
)
296 Reference
< XWindowPeer
> xWindowPeer( Window::GetComponentInterface( sal_False
) );
297 if ( !xWindowPeer
.is() && i_bCreate
)
299 xWindowPeer
.set( new ToolPanelDrawerPeer() );
300 SetComponentInterface( xWindowPeer
);
305 //------------------------------------------------------------------------------------------------------------------
306 Rectangle
ToolPanelDrawer::impl_calcTextBoundingBox() const
308 Font
aFont( GetFont() );
310 aFont
.SetWeight( m_bExpanded
? WEIGHT_BOLD
: WEIGHT_NORMAL
);
311 m_pPaintDevice
->SetFont( aFont
);
313 int nAvailableWidth
= m_pPaintDevice
->GetTextWidth( GetText() );
319 GetSettings().GetStyleSettings().GetTitleHeight()
322 aTextBox
.Top() += ( aTextBox
.GetHeight() - GetTextHeight() ) / 2;
323 aTextBox
.Left() += s_nIndentationWidth
;
324 aTextBox
.Right() -= 1;
326 aTextBox
= m_pPaintDevice
->GetTextRect( aTextBox
, GetText(), impl_getTextStyle() );
330 //------------------------------------------------------------------------------------------------------------------
331 Rectangle
ToolPanelDrawer::impl_calcTitleBarBox( const Rectangle
& i_rTextBox
) const
333 Rectangle
aTitleBarBox( i_rTextBox
);
334 aTitleBarBox
.Bottom() += aTitleBarBox
.Top();
335 aTitleBarBox
.Top() = 0;
336 aTitleBarBox
.Left() = 0;
338 const long nWidth
= GetOutputSizePixel().Width();
339 if ( aTitleBarBox
.GetWidth() < nWidth
)
340 aTitleBarBox
.Right() = nWidth
- 1;
345 //------------------------------------------------------------------------------------------------------------------
346 void ToolPanelDrawer::SetExpanded( const bool i_bExpanded
)
348 if ( m_bExpanded
!= i_bExpanded
)
350 m_bExpanded
= i_bExpanded
;
351 CallEventListeners( m_bExpanded
? VCLEVENT_ITEM_EXPANDED
: VCLEVENT_ITEM_COLLAPSED
);
356 //......................................................................................................................
358 //......................................................................................................................
360 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */