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 "taskpane/TitleBar.hxx"
23 #include "ControlContainerDescriptor.hxx"
24 #include "tools/IconCache.hxx"
25 #include "AccessibleTreeNode.hxx"
26 #include <vcl/decoview.hxx>
27 #include <vcl/window.hxx>
28 #include <vcl/virdev.hxx>
29 #include <osl/mutex.hxx>
30 #include <vcl/svapp.hxx>
31 #include "sdresid.hxx"
32 #include <vcl/bitmap.hxx>
33 #include <vcl/lineinfo.hxx>
34 #include <vcl/bitmapex.hxx>
35 #include <tools/color.hxx>
36 #include <svx/xdash.hxx>
37 #include <svl/itemset.hxx>
38 #include <svx/xlndsit.hxx>
39 #include <svx/xlineit0.hxx>
40 #include <svx/svdobj.hxx>
41 #include <svx/svdpool.hxx>
42 #include <svtools/colorcfg.hxx>
43 #include <svx/xlnclit.hxx>
44 #include <svx/xfillit0.hxx>
45 #include "res_bmp.hrc"
48 namespace sd
{ namespace toolpanel
{
50 const int TitleBar::snIndentationWidth
= 16;
52 TitleBar::TitleBar ( ::Window
* pParent
, const String
& rsTitle
, TitleBarType eType
, bool bIsExpandable
)
53 : ::Window (pParent
, WB_TABSTOP
)
59 , mpDevice(new VirtualDevice (*this))
60 , mbIsExpandable (bIsExpandable
)
62 EnableMapMode (sal_False
);
64 SetBackground (Wallpaper());
66 // Change the mouse pointer shape so that it acts as a mouse over effect.
69 case TBT_SUB_CONTROL_HEADLINE
:
71 SetPointer (POINTER_REFHAND
);
79 TitleBar::~TitleBar (void)
86 Size
TitleBar::GetPreferredSize (void)
88 int nWidth
= GetOutputSizePixel().Width();
89 Rectangle
aTitleBarBox (
91 CalculateTextBoundingBox(nWidth
, true),
94 return aTitleBarBox
.GetSize();
100 sal_Int32
TitleBar::GetPreferredWidth (sal_Int32
)
102 Rectangle
aTitleBarBox (
103 CalculateTitleBarBox(
104 CalculateTextBoundingBox(0, true),
106 return aTitleBarBox
.GetWidth();
112 sal_Int32
TitleBar::GetPreferredHeight (sal_Int32 nWidth
)
114 Rectangle
aTitleBarBox (
115 CalculateTitleBarBox(
116 CalculateTextBoundingBox(nWidth
, true),
119 return aTitleBarBox
.GetHeight();
125 bool TitleBar::IsResizable (void)
133 ::Window
* TitleBar::GetWindow (void)
141 sal_Int32
TitleBar::GetMinimumWidth (void)
149 void TitleBar::Paint (const Rectangle
& rBoundingBox
)
151 mpDevice
->SetMapMode(GetMapMode());
152 mpDevice
->SetOutputSize (GetOutputSizePixel());
153 mpDevice
->SetSettings(GetSettings());
154 mpDevice
->SetDrawMode(GetDrawMode());
158 case TBT_SUB_CONTROL_HEADLINE
:
159 PaintSubPanelHeadLineBar ();
165 GetOutputSizePixel(),
167 GetOutputSizePixel(),
170 ::Window::Paint (rBoundingBox
);
176 bool TitleBar::Expand (bool bFlag
)
178 bool bExpansionStateChanged (bFlag
!=IsExpanded());
181 return bExpansionStateChanged
;
187 bool TitleBar::IsExpanded (void) const
193 void TitleBar::SetEnabledState(bool bFlag
)
205 void TitleBar::GetFocus()
214 void TitleBar::LoseFocus()
223 bool TitleBar::HasExpansionIndicator (void) const
225 bool bHasExpansionIndicator (false);
230 case TBT_SUB_CONTROL_HEADLINE
:
231 bHasExpansionIndicator
= true;
235 return bHasExpansionIndicator
;
241 Image
TitleBar::GetExpansionIndicator (void) const
246 sal_uInt16 nResourceId
= 0;
249 case TBT_SUB_CONTROL_HEADLINE
:
251 nResourceId
= BMP_COLLAPSE
;
253 nResourceId
= BMP_EXPAND
;
255 aIndicator
= IconCache::Instance().GetIcon(nResourceId
);
266 void TitleBar::PaintSubPanelHeadLineBar (void)
268 int nWidth (GetOutputSizePixel().Width());
269 Rectangle
aTextBox (CalculateTextBoundingBox (nWidth
, true));
271 Rectangle
aTitleBarBox (CalculateTitleBarBox(aTextBox
, nWidth
));
272 int nVerticalOffset
= -aTitleBarBox
.Top();
273 aTitleBarBox
.Top() += nVerticalOffset
;
274 aTitleBarBox
.Bottom() += nVerticalOffset
;
275 aTextBox
.Top() += nVerticalOffset
;
276 aTextBox
.Bottom() += nVerticalOffset
;
278 PaintBackground (aTitleBarBox
);
279 Rectangle
aFocusBox (PaintExpansionIndicator (aTextBox
));
280 PaintText (aTextBox
);
282 aFocusBox
.Union (aTextBox
);
283 aFocusBox
.Left() -= 2;
284 aFocusBox
.Right() += 1;
285 PaintFocusIndicator (aFocusBox
);
291 void TitleBar::PaintFocusIndicator (const Rectangle
& rTextBox
)
295 Rectangle
aTextPixelBox (mpDevice
->LogicToPixel (rTextBox
));
296 mpDevice
->EnableMapMode (sal_False
);
297 Rectangle
aBox (rTextBox
);
301 mpDevice
->SetFillColor ();
303 mpDevice
->DrawRect (aTextPixelBox
);
305 LineInfo
aDottedStyle (LINE_DASH
);
306 aDottedStyle
.SetDashCount (0);
307 aDottedStyle
.SetDotCount (1);
308 aDottedStyle
.SetDotLen (1);
309 aDottedStyle
.SetDistance (1);
311 mpDevice
->SetLineColor (COL_BLACK
);
312 mpDevice
->DrawPolyLine (Polygon(aTextPixelBox
), aDottedStyle
);
313 mpDevice
->EnableMapMode (sal_False
);
322 Rectangle
TitleBar::PaintExpansionIndicator (const Rectangle
& rTextBox
)
324 Rectangle aExpansionIndicatorArea
;
326 if (HasExpansionIndicator())
328 Image aImage
= GetExpansionIndicator();
329 int nHeight (aImage
.GetSizePixel().Height());
334 rTextBox
.Top() + (GetTextHeight() - nHeight
) / 2);
335 if (meType
== TBT_SUB_CONTROL_HEADLINE
)
337 mpDevice
->DrawImage (aPosition
, aImage
);
339 aExpansionIndicatorArea
= Rectangle (
340 aPosition
, aImage
.GetSizePixel());
344 return aExpansionIndicatorArea
;
350 void TitleBar::PaintText (const Rectangle
& rTextBox
)
352 mpDevice
->DrawText (rTextBox
, msTitle
, GetTextStyle());
358 sal_uInt16
TitleBar::GetTextStyle (void)
362 return TEXT_DRAW_LEFT
364 | TEXT_DRAW_MULTILINE
365 | TEXT_DRAW_WORDBREAK
;
369 return TEXT_DRAW_DISABLE
;
375 void TitleBar::PaintBackground (const Rectangle
& rTitleBarBox
)
377 // Fill a slightly rounded rectangle.
380 case TBT_SUB_CONTROL_HEADLINE
:
382 Color
aColor (GetSettings().GetStyleSettings().GetDialogColor());
385 // Make the color a little bit darker.
386 aColor
.SetRed(sal_uInt8(((sal_uInt16
)aColor
.GetRed()) * 8 / 10));
387 aColor
.SetGreen(sal_uInt8(((sal_uInt16
)aColor
.GetGreen()) * 8 / 10));
388 aColor
.SetBlue(sal_uInt8(((sal_uInt16
)aColor
.GetBlue()) * 8 / 10));
391 mpDevice
->SetFillColor (aColor
);
392 mpDevice
->SetLineColor ();
393 mpDevice
->DrawRect (rTitleBarBox
);
395 // Erase the four corner pixels to make the rectangle appear
397 mpDevice
->SetLineColor (
398 GetSettings().GetStyleSettings().GetWindowColor());
399 mpDevice
->DrawPixel (
400 rTitleBarBox
.TopLeft());
401 mpDevice
->DrawPixel (
402 Point(rTitleBarBox
.Right(), rTitleBarBox
.Top()));
403 mpDevice
->DrawPixel (
404 Point(rTitleBarBox
.Left(), rTitleBarBox
.Bottom()));
405 mpDevice
->DrawPixel (
406 Point(rTitleBarBox
.Right(), rTitleBarBox
.Bottom()));
415 Rectangle
TitleBar::CalculateTextBoundingBox (
417 bool bEmphasizeExpanded
)
419 // Show the title of expanded controls in bold font.
420 const Font
& rOriginalFont (GetFont());
421 Font
aFont (rOriginalFont
);
422 if (bEmphasizeExpanded
&& mbExpanded
)
423 aFont
.SetWeight (WEIGHT_BOLD
);
425 aFont
.SetWeight (WEIGHT_NORMAL
);
426 mpDevice
->SetFont (aFont
);
428 // Use the natural width of the text when no width is given.
429 if (nAvailableWidth
== 0)
430 nAvailableWidth
= GetTextWidth (msTitle
);
434 Size (nAvailableWidth
,
435 GetSettings().GetStyleSettings().GetTitleHeight()));
436 aTextBox
.Top() += (aTextBox
.GetHeight() - GetTextHeight()) / 2;
437 if (HasExpansionIndicator())
438 aTextBox
.Left() += snIndentationWidth
;
440 aTextBox
.Left() += 3;
441 aTextBox
.Right() -= 1;
443 aTextBox
= mpDevice
->GetTextRect (aTextBox
, msTitle
, GetTextStyle());
451 Rectangle
TitleBar::CalculateTitleBarBox (
452 const Rectangle
& rTextBox
,
455 Rectangle
aTitleBarBox (rTextBox
);
459 case TBT_SUB_CONTROL_HEADLINE
:
460 aTitleBarBox
.Top() -= 3;
461 aTitleBarBox
.Bottom() += 3;
465 aTitleBarBox
.Left() = 0;
466 if (aTitleBarBox
.GetWidth() < nWidth
)
467 aTitleBarBox
.Right() = nWidth
-1;
475 void TitleBar::MouseMove (const MouseEvent
& )
482 void TitleBar::MouseButtonDown (const MouseEvent
& )
484 // Do not forward to parent window so that the mouse button handler of
485 // the docking window is not invoked.
491 void TitleBar::MouseButtonUp (const MouseEvent
& )
493 // Do not forward to parent window so that the mouse button handler of
494 // the docking window is not invoked.
500 void TitleBar::DataChanged (const DataChangedEvent
& rEvent
)
502 ::Window::DataChanged (rEvent
);
504 switch (rEvent
.GetType())
506 case DATACHANGED_SETTINGS
:
507 if ((rEvent
.GetFlags() & SETTINGS_STYLE
) == 0)
509 SetSettings(Application::GetSettings());
510 mpDevice
.reset(new VirtualDevice (*this));
514 case DATACHANGED_FONTS
:
515 case DATACHANGED_FONTSUBSTITUTION
:
517 const StyleSettings
& rStyleSettings (GetSettings().GetStyleSettings());
520 Font aFont
= rStyleSettings
.GetAppFont();
522 aFont
.Merge(GetControlFont());
523 SetZoomedPointFont(aFont
);
527 if (IsControlForeground())
528 aColor
= GetControlForeground();
530 aColor
= rStyleSettings
.GetButtonTextColor();
531 SetTextColor(aColor
);
544 String
TitleBar::GetTitle (void) const
552 ::com::sun::star::uno::Reference
<
553 ::com::sun::star::accessibility::XAccessible
> TitleBar::CreateAccessibleObject (
554 const ::com::sun::star::uno::Reference
<
555 ::com::sun::star::accessibility::XAccessible
>& )
557 return new ::accessibility::AccessibleTreeNode(
561 ::com::sun::star::accessibility::AccessibleRole::LABEL
);
565 } } // end of namespace ::sd::toolpanel
567 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */