Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 : : *
5 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
6 : : *
7 : : * OpenOffice.org - a multi-platform office productivity suite
8 : : *
9 : : * This file is part of OpenOffice.org.
10 : : *
11 : : * OpenOffice.org is free software: you can redistribute it and/or modify
12 : : * it under the terms of the GNU Lesser General Public License version 3
13 : : * only, as published by the Free Software Foundation.
14 : : *
15 : : * OpenOffice.org is distributed in the hope that it will be useful,
16 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : : * GNU Lesser General Public License version 3 for more details
19 : : * (a copy is included in the LICENSE file that accompanied this code).
20 : : *
21 : : * You should have received a copy of the GNU Lesser General Public License
22 : : * version 3 along with OpenOffice.org. If not, see
23 : : * <http://www.openoffice.org/license.html>
24 : : * for a copy of the LGPLv3 License.
25 : : *
26 : : ************************************************************************/
27 : :
28 : :
29 : : #include "toolpaneldrawer.hxx"
30 : : #include "toolpaneldrawerpeer.hxx"
31 : : #include "svtools/svtresid.hxx"
32 : : #include "svtools/svtools.hrc"
33 : :
34 : : #include <com/sun/star/accessibility/AccessibleRole.hpp>
35 : :
36 : : #include <vcl/lineinfo.hxx>
37 : : #include <vcl/image.hxx>
38 : : #include <vcl/svapp.hxx>
39 : : #include <vcl/vclevent.hxx>
40 : :
41 : : //......................................................................................................................
42 : : namespace svt
43 : : {
44 : : //......................................................................................................................
45 : :
46 : : using ::com::sun::star::uno::Reference;
47 : : using ::com::sun::star::awt::XWindowPeer;
48 : : namespace AccessibleRole = ::com::sun::star::accessibility::AccessibleRole;
49 : :
50 : : static const int s_nIndentationWidth = 16;
51 : :
52 : : //==================================================================================================================
53 : : //= DrawerVisualization
54 : : //==================================================================================================================
55 : : //------------------------------------------------------------------------------------------------------------------
56 : 130 : DrawerVisualization::DrawerVisualization( ToolPanelDrawer& i_rParent )
57 : : :Window( &i_rParent )
58 : 130 : ,m_rDrawer( i_rParent )
59 : : {
60 [ + - ]: 130 : SetMouseTransparent( sal_True );
61 [ + - ]: 130 : Show();
62 [ + - ]: 130 : SetAccessibleRole( AccessibleRole::LABEL );
63 : 130 : }
64 : :
65 : : //------------------------------------------------------------------------------------------------------------------
66 : 130 : DrawerVisualization::~DrawerVisualization()
67 : : {
68 [ - + ]: 130 : }
69 : :
70 : : //------------------------------------------------------------------------------------------------------------------
71 : 275 : void DrawerVisualization::Paint( const Rectangle& i_rBoundingBox )
72 : : {
73 : 275 : Window::Paint( i_rBoundingBox );
74 : 275 : m_rDrawer.Paint();
75 : 275 : }
76 : :
77 : : //==================================================================================================================
78 : : //= ToolPanelDrawer
79 : : //==================================================================================================================
80 : : //------------------------------------------------------------------------------------------------------------------
81 : 130 : ToolPanelDrawer::ToolPanelDrawer( Window& i_rParent, const ::rtl::OUString& i_rTitle )
82 : : :Window( &i_rParent, WB_TABSTOP )
83 [ + - ]: 130 : ,m_pPaintDevice( new VirtualDevice( *this ) )
84 : : ,m_aVisualization( *this )
85 : : ,m_bFocused( false )
86 [ + - ][ + - ]: 260 : ,m_bExpanded( false )
87 : : {
88 [ + - ]: 130 : EnableMapMode( sal_False );
89 [ + - ][ + - ]: 130 : SetBackground( Wallpaper() );
[ + - ]
90 [ + - ]: 130 : SetPointer( POINTER_REFHAND );
91 : :
92 [ + - ]: 130 : SetAccessibleRole( AccessibleRole::LIST_ITEM );
93 : :
94 [ + - ][ + - ]: 130 : SetText( i_rTitle );
[ + - ]
95 [ + - ][ + - ]: 130 : SetAccessibleName( i_rTitle );
[ + - ]
96 [ + - ][ + - ]: 130 : SetAccessibleDescription( i_rTitle );
[ + - ]
97 : :
98 [ + - ][ + - ]: 130 : m_aVisualization.SetAccessibleName( i_rTitle );
[ + - ]
99 [ + - ][ + - ]: 130 : m_aVisualization.SetAccessibleDescription( i_rTitle );
[ + - ]
100 : 130 : }
101 : :
102 : : //------------------------------------------------------------------------------------------------------------------
103 [ + - ][ + - ]: 130 : ToolPanelDrawer::~ToolPanelDrawer()
104 : : {
105 [ - + ]: 260 : }
106 : :
107 : : //------------------------------------------------------------------------------------------------------------------
108 : 700 : long ToolPanelDrawer::GetPreferredHeightPixel() const
109 : : {
110 [ + - ][ + - ]: 700 : Rectangle aTitleBarBox( impl_calcTitleBarBox( impl_calcTextBoundingBox() ) );
111 [ + - ]: 700 : return aTitleBarBox.GetHeight();
112 : : }
113 : :
114 : : //------------------------------------------------------------------------------------------------------------------
115 : 275 : void ToolPanelDrawer::Paint()
116 : : {
117 [ + - ]: 275 : m_pPaintDevice->SetMapMode( GetMapMode() );
118 [ + - ]: 275 : m_pPaintDevice->SetOutputSize( GetOutputSizePixel() );
119 [ + - ]: 275 : m_pPaintDevice->SetSettings( GetSettings() );
120 [ + - ]: 275 : m_pPaintDevice->SetDrawMode( GetDrawMode() );
121 : :
122 [ + - ]: 275 : const Rectangle aTextBox( impl_calcTextBoundingBox() );
123 [ + - ][ + - ]: 275 : impl_paintBackground( impl_calcTitleBarBox( aTextBox ) );
124 : :
125 [ + - ]: 275 : Rectangle aFocusBox( impl_paintExpansionIndicator( aTextBox ) );
126 : :
127 [ + - ][ + - ]: 275 : m_pPaintDevice->DrawText( aTextBox, GetText(), impl_getTextStyle() );
[ + - ][ + - ]
128 : :
129 [ + - ]: 275 : aFocusBox.Union( aTextBox );
130 : 275 : aFocusBox.Left() += 2;
131 [ + - ]: 275 : impl_paintFocusIndicator( aFocusBox );
132 : :
133 : : m_aVisualization.DrawOutDev(
134 : 275 : Point(), GetOutputSizePixel(),
135 : 275 : Point(), GetOutputSizePixel(),
136 : 275 : *m_pPaintDevice
137 [ + - ]: 275 : );
138 : 275 : }
139 : :
140 : : //------------------------------------------------------------------------------------------------------------------
141 : 275 : Rectangle ToolPanelDrawer::impl_paintExpansionIndicator( const Rectangle& i_rTextBox )
142 : : {
143 [ + - ]: 275 : Rectangle aExpansionIndicatorArea;
144 : :
145 [ + - ]: 275 : Image aImage( impl_getExpansionIndicator() );
146 [ + - ]: 275 : const int nHeight( aImage.GetSizePixel().Height() );
147 [ + - ]: 275 : if ( nHeight > 0 )
148 : : {
149 : : Point aPosition(
150 : : 0,
151 [ + - ]: 275 : i_rTextBox.Top() + ( GetTextHeight() - nHeight ) / 2
152 : 275 : );
153 [ + - ]: 275 : m_pPaintDevice->DrawImage( aPosition, aImage );
154 : :
155 [ + - ][ + - ]: 275 : aExpansionIndicatorArea = Rectangle( aPosition, aImage.GetSizePixel() );
156 : : }
157 : :
158 [ + - ]: 275 : return aExpansionIndicatorArea;
159 : : }
160 : :
161 : :
162 : 275 : Image ToolPanelDrawer::impl_getExpansionIndicator() const
163 : : {
164 : 275 : sal_uInt16 nResourceId = 0;
165 [ + + ]: 275 : if ( m_bExpanded )
166 : 38 : nResourceId = IMG_TRIANGLE_DOWN;
167 : : else
168 : 237 : nResourceId = IMG_TRIANGLE_RIGHT;
169 [ + - ]: 275 : return Image( SvtResId( nResourceId ) );
170 : : }
171 : :
172 : :
173 : 1250 : sal_uInt16 ToolPanelDrawer::impl_getTextStyle() const
174 : : {
175 : : const sal_uInt16 nBasicStyle = TEXT_DRAW_LEFT
176 : : | TEXT_DRAW_TOP
177 : 1250 : | TEXT_DRAW_WORDBREAK;
178 : :
179 [ + - ]: 1250 : if ( IsEnabled() )
180 : 1250 : return nBasicStyle;
181 : :
182 : 1250 : return nBasicStyle | TEXT_DRAW_DISABLE;
183 : : }
184 : :
185 : : //------------------------------------------------------------------------------------------------------------------
186 : 275 : void ToolPanelDrawer::impl_paintBackground( const Rectangle& i_rTitleBarBox )
187 : : {
188 : 275 : m_pPaintDevice->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
189 : 275 : m_pPaintDevice->DrawRect( i_rTitleBarBox );
190 : :
191 : 275 : m_pPaintDevice->SetFillColor();
192 : 275 : m_pPaintDevice->SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
193 [ + - ]: 275 : m_pPaintDevice->DrawLine( i_rTitleBarBox.TopLeft(), i_rTitleBarBox.TopRight() );
194 [ + - ]: 275 : m_pPaintDevice->DrawLine( i_rTitleBarBox.TopLeft(), i_rTitleBarBox.BottomLeft() );
195 : :
196 : 275 : m_pPaintDevice->SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
197 [ + - ][ + - ]: 275 : m_pPaintDevice->DrawLine( i_rTitleBarBox.BottomLeft(), i_rTitleBarBox.BottomRight() );
198 [ + - ][ + - ]: 275 : m_pPaintDevice->DrawLine( i_rTitleBarBox.TopRight(), i_rTitleBarBox.BottomRight() );
199 : 275 : }
200 : :
201 : : //------------------------------------------------------------------------------------------------------------------
202 : 275 : void ToolPanelDrawer::impl_paintFocusIndicator( const Rectangle& i_rTextBox )
203 : : {
204 [ - + ]: 275 : if ( m_bFocused )
205 : : {
206 [ # # ]: 0 : const Rectangle aTextPixelBox( m_pPaintDevice->LogicToPixel( i_rTextBox ) );
207 : :
208 [ # # ]: 0 : m_pPaintDevice->EnableMapMode( sal_False );
209 [ # # ]: 0 : m_pPaintDevice->SetFillColor();
210 : :
211 : 0 : Rectangle aBox( i_rTextBox );
212 : 0 : aBox.Top() -= 1;
213 : 0 : aBox.Bottom() += 1;
214 : :
215 [ # # ]: 0 : m_pPaintDevice->DrawRect( aTextPixelBox );
216 : :
217 [ # # ]: 0 : LineInfo aDottedStyle( LINE_DASH );
218 [ # # ]: 0 : aDottedStyle.SetDashCount( 0 );
219 [ # # ]: 0 : aDottedStyle.SetDotCount( 1 );
220 [ # # ]: 0 : aDottedStyle.SetDotLen( 1 );
221 [ # # ]: 0 : aDottedStyle.SetDistance( 1 );
222 : :
223 [ # # ]: 0 : m_pPaintDevice->SetLineColor( COL_BLACK );
224 [ # # ][ # # ]: 0 : m_pPaintDevice->DrawPolyLine( Polygon( aTextPixelBox ), aDottedStyle );
[ # # ]
225 [ # # ][ # # ]: 0 : m_pPaintDevice->EnableMapMode( sal_False );
226 : : }
227 : : else
228 : 275 : HideFocus();
229 : 275 : }
230 : :
231 : : //------------------------------------------------------------------------------------------------------------------
232 : 0 : void ToolPanelDrawer::GetFocus()
233 : : {
234 : 0 : m_bFocused = true;
235 : 0 : Invalidate();
236 : 0 : }
237 : :
238 : : //------------------------------------------------------------------------------------------------------------------
239 : 0 : void ToolPanelDrawer::LoseFocus()
240 : : {
241 : 0 : m_bFocused = false;
242 : 0 : Invalidate();
243 : 0 : }
244 : :
245 : : //------------------------------------------------------------------------------------------------------------------
246 : 390 : void ToolPanelDrawer::Resize()
247 : : {
248 : 390 : Window::Resize();
249 [ + - ]: 390 : m_aVisualization.SetPosSizePixel( Point(), GetOutputSizePixel() );
250 : 390 : }
251 : :
252 : : //------------------------------------------------------------------------------------------------------------------
253 : 0 : void ToolPanelDrawer::MouseButtonDown( const MouseEvent& i_rMouseEvent )
254 : : {
255 : : // consume this event, and do not forward to the base class - it would sent a NotifyEvent, which in turn, when
256 : : // we live in a DockingWindow, would start undocking
257 : : (void)i_rMouseEvent;
258 : 0 : }
259 : :
260 : : //------------------------------------------------------------------------------------------------------------------
261 : 0 : void ToolPanelDrawer::DataChanged( const DataChangedEvent& i_rEvent )
262 : : {
263 : 0 : Window::DataChanged( i_rEvent );
264 : :
265 [ # # # ]: 0 : switch ( i_rEvent.GetType() )
266 : : {
267 : : case DATACHANGED_SETTINGS:
268 [ # # ]: 0 : if ( ( i_rEvent.GetFlags() & SETTINGS_STYLE ) == 0 )
269 : 0 : break;
270 : 0 : SetSettings( Application::GetSettings() );
271 [ # # ]: 0 : m_pPaintDevice.reset( new VirtualDevice( *this ) );
272 : :
273 : : // fall through.
274 : :
275 : : case DATACHANGED_FONTS:
276 : : case DATACHANGED_FONTSUBSTITUTION:
277 : : {
278 : 0 : const StyleSettings& rStyleSettings( GetSettings().GetStyleSettings() );
279 : :
280 : : // Font.
281 [ # # ]: 0 : Font aFont = rStyleSettings.GetAppFont();
282 [ # # ][ # # ]: 0 : if ( IsControlFont() )
283 [ # # ][ # # ]: 0 : aFont.Merge( GetControlFont() );
[ # # ]
284 [ # # ]: 0 : SetZoomedPointFont( aFont );
285 : :
286 : : // Color.
287 : 0 : Color aColor;
288 [ # # ][ # # ]: 0 : if ( IsControlForeground() )
289 [ # # ]: 0 : aColor = GetControlForeground();
290 : : else
291 : 0 : aColor = rStyleSettings.GetButtonTextColor();
292 [ # # ]: 0 : SetTextColor( aColor );
293 [ # # ]: 0 : SetTextFillColor();
294 : :
295 [ # # ][ # # ]: 0 : Invalidate();
296 : : }
297 : 0 : break;
298 : : }
299 : 0 : }
300 : :
301 : : //------------------------------------------------------------------------------------------------------------------
302 : 0 : Reference< XWindowPeer > ToolPanelDrawer::GetComponentInterface( sal_Bool i_bCreate )
303 : : {
304 : 0 : Reference< XWindowPeer > xWindowPeer( Window::GetComponentInterface( sal_False ) );
305 [ # # ][ # # ]: 0 : if ( !xWindowPeer.is() && i_bCreate )
[ # # ]
306 : : {
307 [ # # ][ # # ]: 0 : xWindowPeer.set( new ToolPanelDrawerPeer() );
[ # # ]
308 [ # # ]: 0 : SetComponentInterface( xWindowPeer );
309 : : }
310 : 0 : return xWindowPeer;
311 : : }
312 : :
313 : : //------------------------------------------------------------------------------------------------------------------
314 : 975 : Rectangle ToolPanelDrawer::impl_calcTextBoundingBox() const
315 : : {
316 [ + - ]: 975 : Font aFont( GetFont() );
317 [ + + ]: 975 : if ( m_bExpanded )
318 [ + - ][ + - ]: 81 : aFont.SetWeight( m_bExpanded ? WEIGHT_BOLD : WEIGHT_NORMAL );
319 [ + - ]: 975 : m_pPaintDevice->SetFont( aFont );
320 : :
321 [ + - ][ + - ]: 975 : int nAvailableWidth = m_pPaintDevice->GetTextWidth( GetText() );
[ + - ]
322 : :
323 : : Rectangle aTextBox(
324 : : Point(),
325 : : Size(
326 : : nAvailableWidth,
327 : 975 : GetSettings().GetStyleSettings().GetTitleHeight()
328 : : )
329 [ + - ]: 975 : );
330 [ + - ][ + - ]: 975 : aTextBox.Top() += ( aTextBox.GetHeight() - GetTextHeight() ) / 2;
331 : 975 : aTextBox.Left() += s_nIndentationWidth;
332 : 975 : aTextBox.Right() -= 1;
333 : :
334 [ + - ][ + - ]: 975 : aTextBox = m_pPaintDevice->GetTextRect( aTextBox, GetText(), impl_getTextStyle() );
[ + - ][ + - ]
335 [ + - ]: 975 : return aTextBox;
336 : : }
337 : :
338 : : //------------------------------------------------------------------------------------------------------------------
339 : 975 : Rectangle ToolPanelDrawer::impl_calcTitleBarBox( const Rectangle& i_rTextBox ) const
340 : : {
341 : 975 : Rectangle aTitleBarBox( i_rTextBox );
342 : 975 : aTitleBarBox.Bottom() += aTitleBarBox.Top();
343 : 975 : aTitleBarBox.Top() = 0;
344 : 975 : aTitleBarBox.Left() = 0;
345 : :
346 : 975 : const long nWidth = GetOutputSizePixel().Width();
347 [ + + ]: 975 : if ( aTitleBarBox.GetWidth() < nWidth )
348 : 420 : aTitleBarBox.Right() = nWidth - 1;
349 : :
350 : 975 : return aTitleBarBox;
351 : : }
352 : :
353 : : //------------------------------------------------------------------------------------------------------------------
354 : 38 : void ToolPanelDrawer::SetExpanded( const bool i_bExpanded )
355 : : {
356 [ + - ]: 38 : if ( m_bExpanded != i_bExpanded )
357 : : {
358 : 38 : m_bExpanded = i_bExpanded;
359 [ + + ]: 38 : CallEventListeners( m_bExpanded ? VCLEVENT_ITEM_EXPANDED : VCLEVENT_ITEM_COLLAPSED );
360 : 38 : Invalidate();
361 : : }
362 : 38 : }
363 : :
364 : : //......................................................................................................................
365 : : } // namespace svt
366 : : //......................................................................................................................
367 : :
368 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|