fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / toolpanel / TitleBar.cxx
blob9fa8c80bdfabb80e7cd63eb5dff6389af4dda08e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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)
54 , TreeNode(this)
55 , meType(eType)
56 , msTitle(rsTitle)
57 , mbExpanded(false)
58 , mbFocused(false)
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.
67 switch (meType)
69 case TBT_SUB_CONTROL_HEADLINE:
70 if (mbIsExpandable)
71 SetPointer (POINTER_REFHAND);
72 break;
79 TitleBar::~TitleBar (void)
86 Size TitleBar::GetPreferredSize (void)
88 int nWidth = GetOutputSizePixel().Width();
89 Rectangle aTitleBarBox (
90 CalculateTitleBarBox(
91 CalculateTextBoundingBox(nWidth, true),
92 nWidth));
94 return aTitleBarBox.GetSize();
100 sal_Int32 TitleBar::GetPreferredWidth (sal_Int32 )
102 Rectangle aTitleBarBox (
103 CalculateTitleBarBox(
104 CalculateTextBoundingBox(0, true),
105 0));
106 return aTitleBarBox.GetWidth();
112 sal_Int32 TitleBar::GetPreferredHeight (sal_Int32 nWidth)
114 Rectangle aTitleBarBox (
115 CalculateTitleBarBox(
116 CalculateTextBoundingBox(nWidth, true),
117 nWidth));
119 return aTitleBarBox.GetHeight();
125 bool TitleBar::IsResizable (void)
127 return true;
133 ::Window* TitleBar::GetWindow (void)
135 return this;
141 sal_Int32 TitleBar::GetMinimumWidth (void)
143 return 20;
149 void TitleBar::Paint (const Rectangle& rBoundingBox)
151 mpDevice->SetMapMode(GetMapMode());
152 mpDevice->SetOutputSize (GetOutputSizePixel());
153 mpDevice->SetSettings(GetSettings());
154 mpDevice->SetDrawMode(GetDrawMode());
156 switch (meType)
158 case TBT_SUB_CONTROL_HEADLINE:
159 PaintSubPanelHeadLineBar ();
160 break;
163 DrawOutDev (
164 Point(0,0),
165 GetOutputSizePixel(),
166 Point(0,0),
167 GetOutputSizePixel(),
168 *mpDevice);
170 ::Window::Paint (rBoundingBox);
176 bool TitleBar::Expand (bool bFlag)
178 bool bExpansionStateChanged (bFlag!=IsExpanded());
179 mbExpanded = bFlag;
180 Invalidate ();
181 return bExpansionStateChanged;
187 bool TitleBar::IsExpanded (void) const
189 return mbExpanded;
193 void TitleBar::SetEnabledState(bool bFlag)
195 if(bFlag)
196 Enable();
197 else
198 Disable();
199 Invalidate ();
205 void TitleBar::GetFocus()
207 mbFocused = true;
208 Invalidate();
214 void TitleBar::LoseFocus()
216 mbFocused = false;
217 Invalidate();
223 bool TitleBar::HasExpansionIndicator (void) const
225 bool bHasExpansionIndicator (false);
226 if (mbIsExpandable)
228 switch (meType)
230 case TBT_SUB_CONTROL_HEADLINE:
231 bHasExpansionIndicator = true;
232 break;
235 return bHasExpansionIndicator;
241 Image TitleBar::GetExpansionIndicator (void) const
243 Image aIndicator;
244 if (mbIsExpandable)
246 sal_uInt16 nResourceId = 0;
247 switch (meType)
249 case TBT_SUB_CONTROL_HEADLINE:
250 if (mbExpanded)
251 nResourceId = BMP_COLLAPSE;
252 else
253 nResourceId = BMP_EXPAND;
255 aIndicator = IconCache::Instance().GetIcon(nResourceId);
256 break;
260 return aIndicator;
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)
293 if (mbFocused)
295 Rectangle aTextPixelBox (mpDevice->LogicToPixel (rTextBox));
296 mpDevice->EnableMapMode (sal_False);
297 Rectangle aBox (rTextBox);
298 aBox.Top() -= 1;
299 aBox.Bottom() += 1;
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);
315 else
316 HideFocus ();
322 Rectangle TitleBar::PaintExpansionIndicator (const Rectangle& rTextBox)
324 Rectangle aExpansionIndicatorArea;
326 if (HasExpansionIndicator())
328 Image aImage = GetExpansionIndicator();
329 int nHeight (aImage.GetSizePixel().Height());
330 if (nHeight > 0)
332 Point aPosition (
334 rTextBox.Top() + (GetTextHeight() - nHeight) / 2);
335 if (meType == TBT_SUB_CONTROL_HEADLINE)
336 aPosition.X() += 3;
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)
360 if(IsEnabled())
362 return TEXT_DRAW_LEFT
363 | TEXT_DRAW_TOP
364 | TEXT_DRAW_MULTILINE
365 | TEXT_DRAW_WORDBREAK;
367 else
369 return TEXT_DRAW_DISABLE;
375 void TitleBar::PaintBackground (const Rectangle& rTitleBarBox)
377 // Fill a slightly rounded rectangle.
378 switch (meType)
380 case TBT_SUB_CONTROL_HEADLINE:
382 Color aColor (GetSettings().GetStyleSettings().GetDialogColor());
383 if (mbExpanded)
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
396 // rounded.
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()));
408 break;
415 Rectangle TitleBar::CalculateTextBoundingBox (
416 int nAvailableWidth,
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);
424 else
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);
432 Rectangle aTextBox (
433 Point(0,0),
434 Size (nAvailableWidth,
435 GetSettings().GetStyleSettings().GetTitleHeight()));
436 aTextBox.Top() += (aTextBox.GetHeight() - GetTextHeight()) / 2;
437 if (HasExpansionIndicator())
438 aTextBox.Left() += snIndentationWidth;
439 else
440 aTextBox.Left() += 3;
441 aTextBox.Right() -= 1;
443 aTextBox = mpDevice->GetTextRect (aTextBox, msTitle, GetTextStyle());
445 return aTextBox;
451 Rectangle TitleBar::CalculateTitleBarBox (
452 const Rectangle& rTextBox,
453 int nWidth)
455 Rectangle aTitleBarBox (rTextBox);
457 switch (meType)
459 case TBT_SUB_CONTROL_HEADLINE:
460 aTitleBarBox.Top() -= 3;
461 aTitleBarBox.Bottom() += 3;
462 break;
465 aTitleBarBox.Left() = 0;
466 if (aTitleBarBox.GetWidth() < nWidth)
467 aTitleBarBox.Right() = nWidth-1;
469 return aTitleBarBox;
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)
508 break;
509 SetSettings(Application::GetSettings());
510 mpDevice.reset(new VirtualDevice (*this));
512 // fall through.
514 case DATACHANGED_FONTS:
515 case DATACHANGED_FONTSUBSTITUTION:
517 const StyleSettings& rStyleSettings (GetSettings().GetStyleSettings());
519 // Font.
520 Font aFont = rStyleSettings.GetAppFont();
521 if (IsControlFont())
522 aFont.Merge(GetControlFont());
523 SetZoomedPointFont(aFont);
525 // Color.
526 Color aColor;
527 if (IsControlForeground())
528 aColor = GetControlForeground();
529 else
530 aColor = rStyleSettings.GetButtonTextColor();
531 SetTextColor(aColor);
532 SetTextFillColor();
534 Resize();
535 Invalidate();
537 break;
544 String TitleBar::GetTitle (void) const
546 return msTitle;
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(
558 *this,
559 GetTitle(),
560 GetTitle(),
561 ::com::sun::star::accessibility::AccessibleRole::LABEL);
565 } } // end of namespace ::sd::toolpanel
567 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */