1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TitleBar.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "taskpane/TitleBar.hxx"
36 #include "ControlContainerDescriptor.hxx"
37 #include "tools/IconCache.hxx"
38 #include "AccessibleTreeNode.hxx"
39 #include <vcl/decoview.hxx>
40 #include <vcl/window.hxx>
41 #include <vcl/virdev.hxx>
42 #include <vos/mutex.hxx>
43 #include <vcl/svapp.hxx>
44 #include "sdresid.hxx"
45 #include <vcl/bitmap.hxx>
46 #include <vcl/lineinfo.hxx>
47 #include <vcl/bitmapex.hxx>
48 #include <tools/color.hxx>
49 #include <svx/xdash.hxx>
50 #include <svtools/itemset.hxx>
51 #include <svx/xlndsit.hxx>
52 #include <svx/xlineit0.hxx>
53 #include <svx/svdobj.hxx>
54 #include <svx/svdpool.hxx>
55 #include <svtools/colorcfg.hxx>
56 #include <svx/xlnclit.hxx>
57 #include <svx/xfillit0.hxx>
58 #include "res_bmp.hrc"
61 namespace sd
{ namespace toolpanel
{
63 const int TitleBar::snIndentationWidth
= 16;
65 TitleBar::TitleBar ( ::Window
* pParent
, const String
& rsTitle
, TitleBarType eType
, bool bIsExpandable
)
73 , mpDevice(new VirtualDevice (*this))
74 , mbIsExpandable (bIsExpandable
)
76 EnableMapMode (FALSE
);
78 SetBackground (Wallpaper());
80 // Change the mouse pointer shape so that it acts as a mouse over effect.
83 case TBT_WINDOW_TITLE
:
86 case TBT_CONTROL_TITLE
:
87 case TBT_SUB_CONTROL_HEADLINE
:
89 SetPointer (POINTER_REFHAND
);
97 TitleBar::~TitleBar (void)
104 Size
TitleBar::GetPreferredSize (void)
106 int nWidth
= GetOutputSizePixel().Width();
107 Rectangle
aTitleBarBox (
108 CalculateTitleBarBox(
109 CalculateTextBoundingBox(nWidth
, true),
112 return aTitleBarBox
.GetSize();
118 sal_Int32
TitleBar::GetPreferredWidth (sal_Int32
)
120 Rectangle
aTitleBarBox (
121 CalculateTitleBarBox(
122 CalculateTextBoundingBox(0, true),
124 return aTitleBarBox
.GetWidth();
130 sal_Int32
TitleBar::GetPreferredHeight (sal_Int32 nWidth
)
132 Rectangle
aTitleBarBox (
133 CalculateTitleBarBox(
134 CalculateTextBoundingBox(nWidth
, true),
137 return aTitleBarBox
.GetHeight();
143 bool TitleBar::IsResizable (void)
151 ::Window
* TitleBar::GetWindow (void)
159 sal_Int32
TitleBar::GetMinimumWidth (void)
167 void TitleBar::Paint (const Rectangle
& rBoundingBox
)
169 mpDevice
->SetMapMode(GetMapMode());
170 mpDevice
->SetOutputSize (GetOutputSizePixel());
171 mpDevice
->SetSettings(GetSettings());
172 mpDevice
->SetDrawMode(GetDrawMode());
176 case TBT_WINDOW_TITLE
:
177 PaintWindowTitleBar ();
180 case TBT_CONTROL_TITLE
:
181 PaintPanelControlTitle ();
184 case TBT_SUB_CONTROL_HEADLINE
:
185 PaintSubPanelHeadLineBar ();
191 GetOutputSizePixel(),
193 GetOutputSizePixel(),
196 ::Window::Paint (rBoundingBox
);
202 bool TitleBar::Expand (bool bFlag
)
204 bool bExpansionStateChanged (bFlag
!=IsExpanded());
207 return bExpansionStateChanged
;
213 bool TitleBar::IsExpanded (void) const
219 void TitleBar::SetEnabledState(bool bFlag
)
229 void TitleBar::SetFocus (bool bFlag
)
238 void TitleBar::SetMouseOver (bool bFlag
)
240 if (bFlag
!= mbMouseOver
)
250 bool TitleBar::HasExpansionIndicator (void) const
252 bool bHasExpansionIndicator (false);
257 case TBT_CONTROL_TITLE
:
258 case TBT_SUB_CONTROL_HEADLINE
:
259 bHasExpansionIndicator
= true;
263 case TBT_WINDOW_TITLE
:
264 // bHasExpansionIndicator remains false
268 return bHasExpansionIndicator
;
274 Image
TitleBar::GetExpansionIndicator (void) const
277 bool bHighContrastMode (GetSettings().GetStyleSettings().GetHighContrastMode() != 0);
280 USHORT nResourceId
= 0;
283 case TBT_CONTROL_TITLE
:
285 if (bHighContrastMode
)
286 nResourceId
= BMP_TRIANGLE_DOWN_H
;
288 nResourceId
= BMP_TRIANGLE_DOWN
;
290 if (bHighContrastMode
)
291 nResourceId
= BMP_TRIANGLE_RIGHT_H
;
293 nResourceId
= BMP_TRIANGLE_RIGHT
;
295 aIndicator
= IconCache::Instance().GetIcon(nResourceId
);
298 case TBT_SUB_CONTROL_HEADLINE
:
300 if (bHighContrastMode
)
301 nResourceId
= BMP_COLLAPSE_H
;
303 nResourceId
= BMP_COLLAPSE
;
305 if (bHighContrastMode
)
306 nResourceId
= BMP_EXPAND_H
;
308 nResourceId
= BMP_EXPAND
;
310 aIndicator
= IconCache::Instance().GetIcon(nResourceId
);
314 case TBT_WINDOW_TITLE
:
315 // aIndicator remains empty Image.
326 void TitleBar::PaintPanelControlTitle (void)
328 int nWidth (GetOutputSizePixel().Width());
329 Rectangle
aTextBox (CalculateTextBoundingBox (nWidth
, true));
330 PaintBackground(CalculateTitleBarBox(aTextBox
, nWidth
));
331 Rectangle
aFocusBox (PaintExpansionIndicator (aTextBox
));
332 PaintText (aTextBox
);
333 aFocusBox
.Union (aTextBox
);
334 aFocusBox
.Left() += 2;
335 PaintFocusIndicator (aFocusBox
);
336 PaintMouseOverIndicator (aTextBox
);
342 void TitleBar::PaintWindowTitleBar (void)
344 Rectangle
aTextBox (CalculateTextBoundingBox (
345 GetOutputSizePixel().Width(),
348 PaintText (aTextBox
);
349 PaintFocusIndicator (aTextBox
);
355 void TitleBar::PaintSubPanelHeadLineBar (void)
357 int nWidth (GetOutputSizePixel().Width());
358 Rectangle
aTextBox (CalculateTextBoundingBox (nWidth
, true));
360 Rectangle
aTitleBarBox (CalculateTitleBarBox(aTextBox
, nWidth
));
361 int nVerticalOffset
= -aTitleBarBox
.Top();
362 aTitleBarBox
.Top() += nVerticalOffset
;
363 aTitleBarBox
.Bottom() += nVerticalOffset
;
364 aTextBox
.Top() += nVerticalOffset
;
365 aTextBox
.Bottom() += nVerticalOffset
;
367 PaintBackground (aTitleBarBox
);
368 Rectangle
aFocusBox (PaintExpansionIndicator (aTextBox
));
369 PaintText (aTextBox
);
371 aFocusBox
.Union (aTextBox
);
372 aFocusBox
.Left() -= 2;
373 aFocusBox
.Right() += 1;
374 PaintFocusIndicator (aFocusBox
);
375 PaintMouseOverIndicator (aTextBox
);
381 void TitleBar::PaintFocusIndicator (const Rectangle
& rTextBox
)
385 Rectangle
aTextPixelBox (mpDevice
->LogicToPixel (rTextBox
));
386 mpDevice
->EnableMapMode (FALSE
);
387 Rectangle
aBox (rTextBox
);
391 mpDevice
->SetFillColor ();
393 mpDevice
->DrawRect (aTextPixelBox
);
395 LineInfo
aDottedStyle (LINE_DASH
);
396 aDottedStyle
.SetDashCount (0);
397 aDottedStyle
.SetDotCount (1);
398 aDottedStyle
.SetDotLen (1);
399 aDottedStyle
.SetDistance (1);
401 mpDevice
->SetLineColor (COL_BLACK
);
402 mpDevice
->DrawPolyLine (Polygon(aTextPixelBox
), aDottedStyle
);
403 mpDevice
->EnableMapMode (FALSE
);
412 void TitleBar::PaintMouseOverIndicator (const Rectangle
& rTextBox
)
416 Rectangle
aBox (rTextBox
);
417 // Show the line below the focus rectangle (which is painted
418 // after and over the mouse over indicator.)
419 // aBox.Bottom() += 2;
420 // DrawLine (aBox.BottomLeft(), aBox.BottomRight());
427 Rectangle
TitleBar::PaintExpansionIndicator (const Rectangle
& rTextBox
)
429 Rectangle aExpansionIndicatorArea
;
431 if (HasExpansionIndicator())
433 Image aImage
= GetExpansionIndicator();
434 int nHeight (aImage
.GetSizePixel().Height());
439 rTextBox
.Top() + (GetTextHeight() - nHeight
) / 2);
440 if (meType
== TBT_SUB_CONTROL_HEADLINE
)
442 mpDevice
->DrawImage (aPosition
, aImage
);
444 aExpansionIndicatorArea
= Rectangle (
445 aPosition
, aImage
.GetSizePixel());
449 return aExpansionIndicatorArea
;
455 void TitleBar::PaintText (const Rectangle
& rTextBox
)
457 mpDevice
->DrawText (rTextBox
, msTitle
, GetTextStyle());
463 USHORT
TitleBar::GetTextStyle (void)
467 return TEXT_DRAW_LEFT
469 | TEXT_DRAW_MULTILINE
470 | TEXT_DRAW_WORDBREAK
;
474 return TEXT_DRAW_DISABLE
;
480 void TitleBar::PaintBackground (const Rectangle
& rTitleBarBox
)
482 // Fill a slightly rounded rectangle.
483 Color
aFillColor (GetFillColor());
484 Color
aLineColor (GetLineColor());
488 case TBT_CONTROL_TITLE
:
490 mpDevice
->SetFillColor (
491 GetSettings().GetStyleSettings().GetDialogColor());
492 mpDevice
->DrawRect(rTitleBarBox
);
494 mpDevice
->SetFillColor();
495 mpDevice
->SetLineColor (
496 GetSettings().GetStyleSettings().GetLightColor());
498 rTitleBarBox
.TopLeft(),rTitleBarBox
.TopRight());
500 rTitleBarBox
.TopLeft(),rTitleBarBox
.BottomLeft());
502 mpDevice
->SetLineColor (
503 GetSettings().GetStyleSettings().GetShadowColor());
505 rTitleBarBox
.BottomLeft(), rTitleBarBox
.BottomRight());
507 rTitleBarBox
.TopRight(), rTitleBarBox
.BottomRight());
511 case TBT_SUB_CONTROL_HEADLINE
:
513 Color
aColor (GetSettings().GetStyleSettings().GetDialogColor());
516 // Make the color a little bit darker.
517 aColor
.SetRed(UINT8(((UINT16
)aColor
.GetRed()) * 8 / 10));
518 aColor
.SetGreen(UINT8(((UINT16
)aColor
.GetGreen()) * 8 / 10));
519 aColor
.SetBlue(UINT8(((UINT16
)aColor
.GetBlue()) * 8 / 10));
522 mpDevice
->SetFillColor (aColor
);
523 mpDevice
->SetLineColor ();
524 mpDevice
->DrawRect (rTitleBarBox
);
526 // Erase the four corner pixels to make the rectangle appear
528 mpDevice
->SetLineColor (
529 GetSettings().GetStyleSettings().GetWindowColor());
530 mpDevice
->DrawPixel (
531 rTitleBarBox
.TopLeft());
532 mpDevice
->DrawPixel (
533 Point(rTitleBarBox
.Right(), rTitleBarBox
.Top()));
534 mpDevice
->DrawPixel (
535 Point(rTitleBarBox
.Left(), rTitleBarBox
.Bottom()));
536 mpDevice
->DrawPixel (
537 Point(rTitleBarBox
.Right(), rTitleBarBox
.Bottom()));
542 case TBT_WINDOW_TITLE
:
550 Rectangle
TitleBar::CalculateTextBoundingBox (
552 bool bEmphasizeExpanded
)
554 // Show the title of expanded controls in bold font.
555 const Font
& rOriginalFont (GetFont());
556 Font
aFont (rOriginalFont
);
557 if (bEmphasizeExpanded
&& mbExpanded
)
558 aFont
.SetWeight (WEIGHT_BOLD
);
560 aFont
.SetWeight (WEIGHT_NORMAL
);
561 mpDevice
->SetFont (aFont
);
563 // Use the natural width of the text when no width is given.
564 if (nAvailableWidth
== 0)
565 nAvailableWidth
= GetTextWidth (msTitle
);
569 Size (nAvailableWidth
,
570 GetSettings().GetStyleSettings().GetTitleHeight()));
571 aTextBox
.Top() += (aTextBox
.GetHeight() - GetTextHeight()) / 2;
572 if (HasExpansionIndicator())
573 aTextBox
.Left() += snIndentationWidth
;
575 aTextBox
.Left() += 3;
576 aTextBox
.Right() -= 1;
578 aTextBox
= mpDevice
->GetTextRect (aTextBox
, msTitle
, GetTextStyle());
586 Rectangle
TitleBar::CalculateTitleBarBox (
587 const Rectangle
& rTextBox
,
590 Rectangle
aTitleBarBox (rTextBox
);
594 case TBT_WINDOW_TITLE
:
595 aTitleBarBox
.Bottom() += aTitleBarBox
.Top();
596 aTitleBarBox
.Top() = 0;
599 case TBT_CONTROL_TITLE
:
600 aTitleBarBox
.Bottom() += aTitleBarBox
.Top();
601 aTitleBarBox
.Top() = 0;
604 case TBT_SUB_CONTROL_HEADLINE
:
605 aTitleBarBox
.Top() -= 3;
606 aTitleBarBox
.Bottom() += 3;
610 aTitleBarBox
.Left() = 0;
611 if (aTitleBarBox
.GetWidth() < nWidth
)
612 aTitleBarBox
.Right() = nWidth
-1;
620 void TitleBar::MouseMove (const MouseEvent
& rEvent
)
622 Point aRelativePosition
= rEvent
.GetPosPixel() - GetPosPixel();
623 Size aSize
= GetSizePixel();
625 aRelativePosition
.X() >= 0
626 && aRelativePosition
.Y() >= 0
627 && aRelativePosition
.X() < aSize
.Width()
628 && aRelativePosition
.Y() < aSize
.Height());
634 void TitleBar::MouseButtonDown (const MouseEvent
& )
636 // Do not forward to parent window so that the mouse button handler of
637 // the docking window is not invoked.
643 void TitleBar::MouseButtonUp (const MouseEvent
& )
645 // Do not forward to parent window so that the mouse button handler of
646 // the docking window is not invoked.
652 void TitleBar::DataChanged (const DataChangedEvent
& rEvent
)
654 ::Window::DataChanged (rEvent
);
656 switch (rEvent
.GetType())
658 case DATACHANGED_SETTINGS
:
659 if ((rEvent
.GetFlags() & SETTINGS_STYLE
) == 0)
661 SetSettings(Application::GetSettings());
662 mpDevice
.reset(new VirtualDevice (*this));
666 case DATACHANGED_FONTS
:
667 case DATACHANGED_FONTSUBSTITUTION
:
669 const StyleSettings
& rStyleSettings (GetSettings().GetStyleSettings());
672 Font aFont
= rStyleSettings
.GetAppFont();
674 aFont
.Merge(GetControlFont());
675 SetZoomedPointFont(aFont
);
679 if (IsControlForeground())
680 aColor
= GetControlForeground();
682 aColor
= rStyleSettings
.GetButtonTextColor();
683 SetTextColor(aColor
);
696 String
TitleBar::GetTitle (void) const
704 ::com::sun::star::uno::Reference
<
705 ::com::sun::star::accessibility::XAccessible
> TitleBar::CreateAccessibleObject (
706 const ::com::sun::star::uno::Reference
<
707 ::com::sun::star::accessibility::XAccessible
>& )
709 return new ::accessibility::AccessibleTreeNode(
713 ::com::sun::star::accessibility::AccessibleRole::LABEL
);
717 } } // end of namespace ::sd::toolpanel