Update ooo320-m1
[ooovba.git] / sd / source / ui / toolpanel / TitleBar.cxx
blob85c8d0ee73acc0b111e41072bea829df87f39a2e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TitleBar.cxx,v $
10 * $Revision: 1.12 $
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)
66 : ::Window (pParent)
67 , TreeNode(this)
68 , meType(eType)
69 , msTitle(rsTitle)
70 , mbExpanded(false)
71 , mbFocused(false)
72 , mbMouseOver(false)
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.
81 switch (meType)
83 case TBT_WINDOW_TITLE:
84 break;
86 case TBT_CONTROL_TITLE:
87 case TBT_SUB_CONTROL_HEADLINE:
88 if (mbIsExpandable)
89 SetPointer (POINTER_REFHAND);
90 break;
97 TitleBar::~TitleBar (void)
104 Size TitleBar::GetPreferredSize (void)
106 int nWidth = GetOutputSizePixel().Width();
107 Rectangle aTitleBarBox (
108 CalculateTitleBarBox(
109 CalculateTextBoundingBox(nWidth, true),
110 nWidth));
112 return aTitleBarBox.GetSize();
118 sal_Int32 TitleBar::GetPreferredWidth (sal_Int32 )
120 Rectangle aTitleBarBox (
121 CalculateTitleBarBox(
122 CalculateTextBoundingBox(0, true),
123 0));
124 return aTitleBarBox.GetWidth();
130 sal_Int32 TitleBar::GetPreferredHeight (sal_Int32 nWidth)
132 Rectangle aTitleBarBox (
133 CalculateTitleBarBox(
134 CalculateTextBoundingBox(nWidth, true),
135 nWidth));
137 return aTitleBarBox.GetHeight();
143 bool TitleBar::IsResizable (void)
145 return true;
151 ::Window* TitleBar::GetWindow (void)
153 return this;
159 sal_Int32 TitleBar::GetMinimumWidth (void)
161 return 20;
167 void TitleBar::Paint (const Rectangle& rBoundingBox)
169 mpDevice->SetMapMode(GetMapMode());
170 mpDevice->SetOutputSize (GetOutputSizePixel());
171 mpDevice->SetSettings(GetSettings());
172 mpDevice->SetDrawMode(GetDrawMode());
174 switch (meType)
176 case TBT_WINDOW_TITLE:
177 PaintWindowTitleBar ();
178 break;
180 case TBT_CONTROL_TITLE:
181 PaintPanelControlTitle ();
182 break;
184 case TBT_SUB_CONTROL_HEADLINE:
185 PaintSubPanelHeadLineBar ();
186 break;
189 DrawOutDev (
190 Point(0,0),
191 GetOutputSizePixel(),
192 Point(0,0),
193 GetOutputSizePixel(),
194 *mpDevice);
196 ::Window::Paint (rBoundingBox);
202 bool TitleBar::Expand (bool bFlag)
204 bool bExpansionStateChanged (bFlag!=IsExpanded());
205 mbExpanded = bFlag;
206 Invalidate ();
207 return bExpansionStateChanged;
213 bool TitleBar::IsExpanded (void) const
215 return mbExpanded;
219 void TitleBar::SetEnabledState(bool bFlag)
221 if(bFlag)
222 Enable();
223 else
224 Disable();
225 Invalidate ();
229 void TitleBar::SetFocus (bool bFlag)
231 mbFocused = bFlag;
232 Invalidate ();
238 void TitleBar::SetMouseOver (bool bFlag)
240 if (bFlag != mbMouseOver)
242 mbMouseOver = bFlag;
243 // Invalidate();
250 bool TitleBar::HasExpansionIndicator (void) const
252 bool bHasExpansionIndicator (false);
253 if (mbIsExpandable)
255 switch (meType)
257 case TBT_CONTROL_TITLE:
258 case TBT_SUB_CONTROL_HEADLINE:
259 bHasExpansionIndicator = true;
260 break;
262 default:
263 case TBT_WINDOW_TITLE:
264 // bHasExpansionIndicator remains false
265 break;
268 return bHasExpansionIndicator;
274 Image TitleBar::GetExpansionIndicator (void) const
276 Image aIndicator;
277 bool bHighContrastMode (GetSettings().GetStyleSettings().GetHighContrastMode() != 0);
278 if (mbIsExpandable)
280 USHORT nResourceId = 0;
281 switch (meType)
283 case TBT_CONTROL_TITLE:
284 if (mbExpanded)
285 if (bHighContrastMode)
286 nResourceId = BMP_TRIANGLE_DOWN_H;
287 else
288 nResourceId = BMP_TRIANGLE_DOWN;
289 else
290 if (bHighContrastMode)
291 nResourceId = BMP_TRIANGLE_RIGHT_H;
292 else
293 nResourceId = BMP_TRIANGLE_RIGHT;
295 aIndicator = IconCache::Instance().GetIcon(nResourceId);
296 break;
298 case TBT_SUB_CONTROL_HEADLINE:
299 if (mbExpanded)
300 if (bHighContrastMode)
301 nResourceId = BMP_COLLAPSE_H;
302 else
303 nResourceId = BMP_COLLAPSE;
304 else
305 if (bHighContrastMode)
306 nResourceId = BMP_EXPAND_H;
307 else
308 nResourceId = BMP_EXPAND;
310 aIndicator = IconCache::Instance().GetIcon(nResourceId);
311 break;
313 default:
314 case TBT_WINDOW_TITLE:
315 // aIndicator remains empty Image.
316 break;
320 return aIndicator;
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(),
346 true));
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)
383 if (mbFocused)
385 Rectangle aTextPixelBox (mpDevice->LogicToPixel (rTextBox));
386 mpDevice->EnableMapMode (FALSE);
387 Rectangle aBox (rTextBox);
388 aBox.Top() -= 1;
389 aBox.Bottom() += 1;
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);
405 else
406 HideFocus ();
412 void TitleBar::PaintMouseOverIndicator (const Rectangle& rTextBox)
414 if (mbMouseOver)
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());
435 if (nHeight > 0)
437 Point aPosition (
439 rTextBox.Top() + (GetTextHeight() - nHeight) / 2);
440 if (meType == TBT_SUB_CONTROL_HEADLINE)
441 aPosition.X() += 3;
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)
465 if(IsEnabled())
467 return TEXT_DRAW_LEFT
468 | TEXT_DRAW_TOP
469 | TEXT_DRAW_MULTILINE
470 | TEXT_DRAW_WORDBREAK;
472 else
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());
486 switch (meType)
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());
497 mpDevice->DrawLine(
498 rTitleBarBox.TopLeft(),rTitleBarBox.TopRight());
499 mpDevice->DrawLine(
500 rTitleBarBox.TopLeft(),rTitleBarBox.BottomLeft());
502 mpDevice->SetLineColor (
503 GetSettings().GetStyleSettings().GetShadowColor());
504 mpDevice-> DrawLine(
505 rTitleBarBox.BottomLeft(), rTitleBarBox.BottomRight());
506 mpDevice->DrawLine(
507 rTitleBarBox.TopRight(), rTitleBarBox.BottomRight());
509 break;
511 case TBT_SUB_CONTROL_HEADLINE:
513 Color aColor (GetSettings().GetStyleSettings().GetDialogColor());
514 if (mbExpanded)
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
527 // rounded.
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()));
539 break;
541 default:
542 case TBT_WINDOW_TITLE:
543 break;
550 Rectangle TitleBar::CalculateTextBoundingBox (
551 int nAvailableWidth,
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);
559 else
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);
567 Rectangle aTextBox (
568 Point(0,0),
569 Size (nAvailableWidth,
570 GetSettings().GetStyleSettings().GetTitleHeight()));
571 aTextBox.Top() += (aTextBox.GetHeight() - GetTextHeight()) / 2;
572 if (HasExpansionIndicator())
573 aTextBox.Left() += snIndentationWidth;
574 else
575 aTextBox.Left() += 3;
576 aTextBox.Right() -= 1;
578 aTextBox = mpDevice->GetTextRect (aTextBox, msTitle, GetTextStyle());
580 return aTextBox;
586 Rectangle TitleBar::CalculateTitleBarBox (
587 const Rectangle& rTextBox,
588 int nWidth)
590 Rectangle aTitleBarBox (rTextBox);
592 switch (meType)
594 case TBT_WINDOW_TITLE:
595 aTitleBarBox.Bottom() += aTitleBarBox.Top();
596 aTitleBarBox.Top() = 0;
597 break;
599 case TBT_CONTROL_TITLE:
600 aTitleBarBox.Bottom() += aTitleBarBox.Top();
601 aTitleBarBox.Top() = 0;
602 break;
604 case TBT_SUB_CONTROL_HEADLINE:
605 aTitleBarBox.Top() -= 3;
606 aTitleBarBox.Bottom() += 3;
607 break;
610 aTitleBarBox.Left() = 0;
611 if (aTitleBarBox.GetWidth() < nWidth)
612 aTitleBarBox.Right() = nWidth-1;
614 return aTitleBarBox;
620 void TitleBar::MouseMove (const MouseEvent& rEvent)
622 Point aRelativePosition = rEvent.GetPosPixel() - GetPosPixel();
623 Size aSize = GetSizePixel();
624 SetMouseOver (
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)
660 break;
661 SetSettings(Application::GetSettings());
662 mpDevice.reset(new VirtualDevice (*this));
664 // fall through.
666 case DATACHANGED_FONTS:
667 case DATACHANGED_FONTSUBSTITUTION:
669 const StyleSettings& rStyleSettings (GetSettings().GetStyleSettings());
671 // Font.
672 Font aFont = rStyleSettings.GetAppFont();
673 if (IsControlFont())
674 aFont.Merge(GetControlFont());
675 SetZoomedPointFont(aFont);
677 // Color.
678 Color aColor;
679 if (IsControlForeground())
680 aColor = GetControlForeground();
681 else
682 aColor = rStyleSettings.GetButtonTextColor();
683 SetTextColor(aColor);
684 SetTextFillColor();
686 Resize();
687 Invalidate();
689 break;
696 String TitleBar::GetTitle (void) const
698 return msTitle;
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(
710 *this,
711 GetTitle(),
712 GetTitle(),
713 ::com::sun::star::accessibility::AccessibleRole::LABEL);
717 } } // end of namespace ::sd::toolpanel