Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "taskpane/TitleBar.hxx"
31 : :
32 : : #include "ControlContainerDescriptor.hxx"
33 : : #include "tools/IconCache.hxx"
34 : : #include "AccessibleTreeNode.hxx"
35 : : #include <vcl/decoview.hxx>
36 : : #include <vcl/window.hxx>
37 : : #include <vcl/virdev.hxx>
38 : : #include <osl/mutex.hxx>
39 : : #include <vcl/svapp.hxx>
40 : : #include "sdresid.hxx"
41 : : #include <vcl/bitmap.hxx>
42 : : #include <vcl/lineinfo.hxx>
43 : : #include <vcl/bitmapex.hxx>
44 : : #include <tools/color.hxx>
45 : : #include <svx/xdash.hxx>
46 : : #include <svl/itemset.hxx>
47 : : #include <svx/xlndsit.hxx>
48 : : #include <svx/xlineit0.hxx>
49 : : #include <svx/svdobj.hxx>
50 : : #include <svx/svdpool.hxx>
51 : : #include <svtools/colorcfg.hxx>
52 : : #include <svx/xlnclit.hxx>
53 : : #include <svx/xfillit0.hxx>
54 : : #include "res_bmp.hrc"
55 : :
56 : :
57 : : namespace sd { namespace toolpanel {
58 : :
59 : : const int TitleBar::snIndentationWidth = 16;
60 : :
61 : 0 : TitleBar::TitleBar ( ::Window* pParent, const String& rsTitle, TitleBarType eType, bool bIsExpandable)
62 : : : ::Window (pParent, WB_TABSTOP)
63 : : , TreeNode(this)
64 : : , meType(eType)
65 : : , msTitle(rsTitle)
66 : : , mbExpanded(false)
67 : : , mbFocused(false)
68 [ # # ]: 0 : , mpDevice(new VirtualDevice (*this))
69 [ # # ][ # # ]: 0 : , mbIsExpandable (bIsExpandable)
[ # # ]
70 : : {
71 [ # # ]: 0 : EnableMapMode (sal_False);
72 : :
73 [ # # ][ # # ]: 0 : SetBackground (Wallpaper());
[ # # ]
74 : :
75 : : // Change the mouse pointer shape so that it acts as a mouse over effect.
76 [ # # ]: 0 : switch (meType)
77 : : {
78 : : case TBT_SUB_CONTROL_HEADLINE:
79 [ # # ]: 0 : if (mbIsExpandable)
80 [ # # ]: 0 : SetPointer (POINTER_REFHAND);
81 : 0 : break;
82 : : }
83 : 0 : }
84 : :
85 : :
86 : :
87 : :
88 [ # # ][ # # ]: 0 : TitleBar::~TitleBar (void)
[ # # ]
89 : : {
90 [ # # ]: 0 : }
91 : :
92 : :
93 : :
94 : :
95 : 0 : Size TitleBar::GetPreferredSize (void)
96 : : {
97 : 0 : int nWidth = GetOutputSizePixel().Width();
98 : : Rectangle aTitleBarBox (
99 : : CalculateTitleBarBox(
100 : : CalculateTextBoundingBox(nWidth, true),
101 [ # # ][ # # ]: 0 : nWidth));
102 : :
103 [ # # ]: 0 : return aTitleBarBox.GetSize();
104 : : }
105 : :
106 : :
107 : :
108 : :
109 : 0 : sal_Int32 TitleBar::GetPreferredWidth (sal_Int32 )
110 : : {
111 : : Rectangle aTitleBarBox (
112 : : CalculateTitleBarBox(
113 : : CalculateTextBoundingBox(0, true),
114 [ # # ][ # # ]: 0 : 0));
115 [ # # ]: 0 : return aTitleBarBox.GetWidth();
116 : : }
117 : :
118 : :
119 : :
120 : :
121 : 0 : sal_Int32 TitleBar::GetPreferredHeight (sal_Int32 nWidth)
122 : : {
123 : : Rectangle aTitleBarBox (
124 : : CalculateTitleBarBox(
125 : : CalculateTextBoundingBox(nWidth, true),
126 [ # # ][ # # ]: 0 : nWidth));
127 : :
128 [ # # ]: 0 : return aTitleBarBox.GetHeight();
129 : : }
130 : :
131 : :
132 : :
133 : :
134 : 0 : bool TitleBar::IsResizable (void)
135 : : {
136 : 0 : return true;
137 : : }
138 : :
139 : :
140 : :
141 : :
142 : 0 : ::Window* TitleBar::GetWindow (void)
143 : : {
144 : 0 : return this;
145 : : }
146 : :
147 : :
148 : :
149 : :
150 : 0 : sal_Int32 TitleBar::GetMinimumWidth (void)
151 : : {
152 : 0 : return 20;
153 : : }
154 : :
155 : :
156 : :
157 : :
158 : 0 : void TitleBar::Paint (const Rectangle& rBoundingBox)
159 : : {
160 : 0 : mpDevice->SetMapMode(GetMapMode());
161 [ # # ]: 0 : mpDevice->SetOutputSize (GetOutputSizePixel());
162 : 0 : mpDevice->SetSettings(GetSettings());
163 : 0 : mpDevice->SetDrawMode(GetDrawMode());
164 : :
165 [ # # ]: 0 : switch (meType)
166 : : {
167 : : case TBT_SUB_CONTROL_HEADLINE:
168 : 0 : PaintSubPanelHeadLineBar ();
169 : 0 : break;
170 : : }
171 : :
172 : : DrawOutDev (
173 : : Point(0,0),
174 : 0 : GetOutputSizePixel(),
175 : : Point(0,0),
176 : 0 : GetOutputSizePixel(),
177 [ # # ]: 0 : *mpDevice);
178 : :
179 : 0 : ::Window::Paint (rBoundingBox);
180 : 0 : }
181 : :
182 : :
183 : :
184 : :
185 : 0 : bool TitleBar::Expand (bool bFlag)
186 : : {
187 : 0 : bool bExpansionStateChanged (bFlag!=IsExpanded());
188 : 0 : mbExpanded = bFlag;
189 : 0 : Invalidate ();
190 : 0 : return bExpansionStateChanged;
191 : : }
192 : :
193 : :
194 : :
195 : :
196 : 0 : bool TitleBar::IsExpanded (void) const
197 : : {
198 : 0 : return mbExpanded;
199 : : }
200 : :
201 : :
202 : 0 : void TitleBar::SetEnabledState(bool bFlag)
203 : : {
204 [ # # ]: 0 : if(bFlag)
205 : 0 : Enable();
206 : : else
207 : 0 : Disable();
208 : 0 : Invalidate ();
209 : 0 : }
210 : :
211 : :
212 : :
213 : :
214 : 0 : void TitleBar::GetFocus()
215 : : {
216 : 0 : mbFocused = true;
217 : 0 : Invalidate();
218 : 0 : }
219 : :
220 : :
221 : :
222 : :
223 : 0 : void TitleBar::LoseFocus()
224 : : {
225 : 0 : mbFocused = false;
226 : 0 : Invalidate();
227 : 0 : }
228 : :
229 : :
230 : :
231 : :
232 : 0 : bool TitleBar::HasExpansionIndicator (void) const
233 : : {
234 : 0 : bool bHasExpansionIndicator (false);
235 [ # # ]: 0 : if (mbIsExpandable)
236 : : {
237 [ # # ]: 0 : switch (meType)
238 : : {
239 : : case TBT_SUB_CONTROL_HEADLINE:
240 : 0 : bHasExpansionIndicator = true;
241 : 0 : break;
242 : : }
243 : : }
244 : 0 : return bHasExpansionIndicator;
245 : : }
246 : :
247 : :
248 : :
249 : :
250 : 0 : Image TitleBar::GetExpansionIndicator (void) const
251 : : {
252 : 0 : Image aIndicator;
253 [ # # ]: 0 : if (mbIsExpandable)
254 : : {
255 : 0 : sal_uInt16 nResourceId = 0;
256 [ # # ]: 0 : switch (meType)
257 : : {
258 : : case TBT_SUB_CONTROL_HEADLINE:
259 [ # # ]: 0 : if (mbExpanded)
260 : 0 : nResourceId = BMP_COLLAPSE;
261 : : else
262 : 0 : nResourceId = BMP_EXPAND;
263 : :
264 [ # # ][ # # ]: 0 : aIndicator = IconCache::Instance().GetIcon(nResourceId);
[ # # ][ # # ]
265 : 0 : break;
266 : : }
267 : : }
268 : :
269 : 0 : return aIndicator;
270 : : }
271 : :
272 : :
273 : :
274 : :
275 : 0 : void TitleBar::PaintSubPanelHeadLineBar (void)
276 : : {
277 : 0 : int nWidth (GetOutputSizePixel().Width());
278 [ # # ]: 0 : Rectangle aTextBox (CalculateTextBoundingBox (nWidth, true));
279 : :
280 [ # # ]: 0 : Rectangle aTitleBarBox (CalculateTitleBarBox(aTextBox, nWidth));
281 : 0 : int nVerticalOffset = -aTitleBarBox.Top();
282 : 0 : aTitleBarBox.Top() += nVerticalOffset;
283 : 0 : aTitleBarBox.Bottom() += nVerticalOffset;
284 : 0 : aTextBox.Top() += nVerticalOffset;
285 : 0 : aTextBox.Bottom() += nVerticalOffset;
286 : :
287 [ # # ]: 0 : PaintBackground (aTitleBarBox);
288 [ # # ]: 0 : Rectangle aFocusBox (PaintExpansionIndicator (aTextBox));
289 [ # # ]: 0 : PaintText (aTextBox);
290 : :
291 [ # # ]: 0 : aFocusBox.Union (aTextBox);
292 : 0 : aFocusBox.Left() -= 2;
293 : 0 : aFocusBox.Right() += 1;
294 [ # # ]: 0 : PaintFocusIndicator (aFocusBox);
295 : 0 : }
296 : :
297 : :
298 : :
299 : :
300 : 0 : void TitleBar::PaintFocusIndicator (const Rectangle& rTextBox)
301 : : {
302 [ # # ]: 0 : if (mbFocused)
303 : : {
304 [ # # ]: 0 : Rectangle aTextPixelBox (mpDevice->LogicToPixel (rTextBox));
305 [ # # ]: 0 : mpDevice->EnableMapMode (sal_False);
306 : 0 : Rectangle aBox (rTextBox);
307 : 0 : aBox.Top() -= 1;
308 : 0 : aBox.Bottom() += 1;
309 : :
310 [ # # ]: 0 : mpDevice->SetFillColor ();
311 : :
312 [ # # ]: 0 : mpDevice->DrawRect (aTextPixelBox);
313 : :
314 [ # # ]: 0 : LineInfo aDottedStyle (LINE_DASH);
315 [ # # ]: 0 : aDottedStyle.SetDashCount (0);
316 [ # # ]: 0 : aDottedStyle.SetDotCount (1);
317 [ # # ]: 0 : aDottedStyle.SetDotLen (1);
318 [ # # ]: 0 : aDottedStyle.SetDistance (1);
319 : :
320 [ # # ]: 0 : mpDevice->SetLineColor (COL_BLACK);
321 [ # # ][ # # ]: 0 : mpDevice->DrawPolyLine (Polygon(aTextPixelBox), aDottedStyle);
[ # # ]
322 [ # # ][ # # ]: 0 : mpDevice->EnableMapMode (sal_False);
323 : : }
324 : : else
325 : 0 : HideFocus ();
326 : 0 : }
327 : :
328 : :
329 : :
330 : :
331 : 0 : Rectangle TitleBar::PaintExpansionIndicator (const Rectangle& rTextBox)
332 : : {
333 : 0 : Rectangle aExpansionIndicatorArea;
334 : :
335 [ # # ]: 0 : if (HasExpansionIndicator())
336 : : {
337 [ # # ]: 0 : Image aImage = GetExpansionIndicator();
338 [ # # ]: 0 : int nHeight (aImage.GetSizePixel().Height());
339 [ # # ]: 0 : if (nHeight > 0)
340 : : {
341 : : Point aPosition (
342 : : 0,
343 [ # # ]: 0 : rTextBox.Top() + (GetTextHeight() - nHeight) / 2);
344 [ # # ]: 0 : if (meType == TBT_SUB_CONTROL_HEADLINE)
345 : 0 : aPosition.X() += 3;
346 [ # # ]: 0 : mpDevice->DrawImage (aPosition, aImage);
347 : :
348 : : aExpansionIndicatorArea = Rectangle (
349 [ # # ][ # # ]: 0 : aPosition, aImage.GetSizePixel());
350 [ # # ]: 0 : }
351 : : }
352 : :
353 : 0 : return aExpansionIndicatorArea;
354 : : }
355 : :
356 : :
357 : :
358 : :
359 : 0 : void TitleBar::PaintText (const Rectangle& rTextBox)
360 : : {
361 : 0 : mpDevice->DrawText (rTextBox, msTitle, GetTextStyle());
362 : 0 : }
363 : :
364 : :
365 : :
366 : :
367 : 0 : sal_uInt16 TitleBar::GetTextStyle (void)
368 : : {
369 [ # # ]: 0 : if(IsEnabled())
370 : : {
371 : : return TEXT_DRAW_LEFT
372 : : | TEXT_DRAW_TOP
373 : : | TEXT_DRAW_MULTILINE
374 : 0 : | TEXT_DRAW_WORDBREAK;
375 : : }
376 : : else
377 : : {
378 : 0 : return TEXT_DRAW_DISABLE;
379 : : }
380 : : }
381 : :
382 : :
383 : :
384 : 0 : void TitleBar::PaintBackground (const Rectangle& rTitleBarBox)
385 : : {
386 : : // Fill a slightly rounded rectangle.
387 [ # # ]: 0 : switch (meType)
388 : : {
389 : : case TBT_SUB_CONTROL_HEADLINE:
390 : : {
391 : 0 : Color aColor (GetSettings().GetStyleSettings().GetDialogColor());
392 [ # # ]: 0 : if (mbExpanded)
393 : : {
394 : : // Make the color a little bit darker.
395 [ # # ]: 0 : aColor.SetRed(sal_uInt8(((sal_uInt16)aColor.GetRed()) * 8 / 10));
396 [ # # ]: 0 : aColor.SetGreen(sal_uInt8(((sal_uInt16)aColor.GetGreen()) * 8 / 10));
397 [ # # ]: 0 : aColor.SetBlue(sal_uInt8(((sal_uInt16)aColor.GetBlue()) * 8 / 10));
398 : : }
399 : :
400 [ # # ]: 0 : mpDevice->SetFillColor (aColor);
401 [ # # ]: 0 : mpDevice->SetLineColor ();
402 [ # # ]: 0 : mpDevice->DrawRect (rTitleBarBox);
403 : :
404 : : // Erase the four corner pixels to make the rectangle appear
405 : : // rounded.
406 : 0 : mpDevice->SetLineColor (
407 [ # # ]: 0 : GetSettings().GetStyleSettings().GetWindowColor());
408 : 0 : mpDevice->DrawPixel (
409 [ # # ]: 0 : rTitleBarBox.TopLeft());
410 : 0 : mpDevice->DrawPixel (
411 [ # # ]: 0 : Point(rTitleBarBox.Right(), rTitleBarBox.Top()));
412 : 0 : mpDevice->DrawPixel (
413 [ # # ]: 0 : Point(rTitleBarBox.Left(), rTitleBarBox.Bottom()));
414 : 0 : mpDevice->DrawPixel (
415 [ # # ]: 0 : Point(rTitleBarBox.Right(), rTitleBarBox.Bottom()));
416 : : }
417 : 0 : break;
418 : : }
419 : 0 : }
420 : :
421 : :
422 : :
423 : :
424 : 0 : Rectangle TitleBar::CalculateTextBoundingBox (
425 : : int nAvailableWidth,
426 : : bool bEmphasizeExpanded)
427 : : {
428 : : // Show the title of expanded controls in bold font.
429 : 0 : const Font& rOriginalFont (GetFont());
430 [ # # ]: 0 : Font aFont (rOriginalFont);
431 [ # # ][ # # ]: 0 : if (bEmphasizeExpanded && mbExpanded)
432 [ # # ]: 0 : aFont.SetWeight (WEIGHT_BOLD);
433 : : else
434 [ # # ]: 0 : aFont.SetWeight (WEIGHT_NORMAL);
435 [ # # ]: 0 : mpDevice->SetFont (aFont);
436 : :
437 : : // Use the natural width of the text when no width is given.
438 [ # # ]: 0 : if (nAvailableWidth == 0)
439 [ # # ]: 0 : nAvailableWidth = GetTextWidth (msTitle);
440 : :
441 : : Rectangle aTextBox (
442 : : Point(0,0),
443 : : Size (nAvailableWidth,
444 [ # # ]: 0 : GetSettings().GetStyleSettings().GetTitleHeight()));
445 [ # # ][ # # ]: 0 : aTextBox.Top() += (aTextBox.GetHeight() - GetTextHeight()) / 2;
446 [ # # ]: 0 : if (HasExpansionIndicator())
447 : 0 : aTextBox.Left() += snIndentationWidth;
448 : : else
449 : 0 : aTextBox.Left() += 3;
450 : 0 : aTextBox.Right() -= 1;
451 : :
452 [ # # ][ # # ]: 0 : aTextBox = mpDevice->GetTextRect (aTextBox, msTitle, GetTextStyle());
453 : :
454 [ # # ]: 0 : return aTextBox;
455 : : }
456 : :
457 : :
458 : :
459 : :
460 : 0 : Rectangle TitleBar::CalculateTitleBarBox (
461 : : const Rectangle& rTextBox,
462 : : int nWidth)
463 : : {
464 : 0 : Rectangle aTitleBarBox (rTextBox);
465 : :
466 [ # # ]: 0 : switch (meType)
467 : : {
468 : : case TBT_SUB_CONTROL_HEADLINE:
469 : 0 : aTitleBarBox.Top() -= 3;
470 : 0 : aTitleBarBox.Bottom() += 3;
471 : 0 : break;
472 : :
473 : : }
474 : 0 : aTitleBarBox.Left() = 0;
475 [ # # ]: 0 : if (aTitleBarBox.GetWidth() < nWidth)
476 : 0 : aTitleBarBox.Right() = nWidth-1;
477 : :
478 : 0 : return aTitleBarBox;
479 : : }
480 : :
481 : :
482 : :
483 : :
484 : 0 : void TitleBar::MouseMove (const MouseEvent& )
485 : : {
486 : 0 : }
487 : :
488 : :
489 : :
490 : :
491 : 0 : void TitleBar::MouseButtonDown (const MouseEvent& )
492 : : {
493 : : // Do not forward to parent window so that the mouse button handler of
494 : : // the docking window is not invoked.
495 : 0 : }
496 : :
497 : :
498 : :
499 : :
500 : 0 : void TitleBar::MouseButtonUp (const MouseEvent& )
501 : : {
502 : : // Do not forward to parent window so that the mouse button handler of
503 : : // the docking window is not invoked.
504 : 0 : }
505 : :
506 : :
507 : :
508 : :
509 : 0 : void TitleBar::DataChanged (const DataChangedEvent& rEvent)
510 : : {
511 : 0 : ::Window::DataChanged (rEvent);
512 : :
513 [ # # # ]: 0 : switch (rEvent.GetType())
514 : : {
515 : : case DATACHANGED_SETTINGS:
516 [ # # ]: 0 : if ((rEvent.GetFlags() & SETTINGS_STYLE) == 0)
517 : 0 : break;
518 : 0 : SetSettings(Application::GetSettings());
519 [ # # ]: 0 : mpDevice.reset(new VirtualDevice (*this));
520 : :
521 : : // fall through.
522 : :
523 : : case DATACHANGED_FONTS:
524 : : case DATACHANGED_FONTSUBSTITUTION:
525 : : {
526 : 0 : const StyleSettings& rStyleSettings (GetSettings().GetStyleSettings());
527 : :
528 : : // Font.
529 [ # # ]: 0 : Font aFont = rStyleSettings.GetAppFont();
530 [ # # ][ # # ]: 0 : if (IsControlFont())
531 [ # # ][ # # ]: 0 : aFont.Merge(GetControlFont());
[ # # ]
532 [ # # ]: 0 : SetZoomedPointFont(aFont);
533 : :
534 : : // Color.
535 : 0 : Color aColor;
536 [ # # ][ # # ]: 0 : if (IsControlForeground())
537 [ # # ]: 0 : aColor = GetControlForeground();
538 : : else
539 : 0 : aColor = rStyleSettings.GetButtonTextColor();
540 [ # # ]: 0 : SetTextColor(aColor);
541 [ # # ]: 0 : SetTextFillColor();
542 : :
543 [ # # ]: 0 : Resize();
544 [ # # ][ # # ]: 0 : Invalidate();
545 : : }
546 : 0 : break;
547 : : }
548 : 0 : }
549 : :
550 : :
551 : :
552 : :
553 : 0 : String TitleBar::GetTitle (void) const
554 : : {
555 : 0 : return msTitle;
556 : : }
557 : :
558 : :
559 : :
560 : :
561 : : ::com::sun::star::uno::Reference<
562 : 0 : ::com::sun::star::accessibility::XAccessible > TitleBar::CreateAccessibleObject (
563 : : const ::com::sun::star::uno::Reference<
564 : : ::com::sun::star::accessibility::XAccessible>& )
565 : : {
566 : : return new ::accessibility::AccessibleTreeNode(
567 : : *this,
568 : : GetTitle(),
569 : : GetTitle(),
570 [ # # ][ # # ]: 0 : ::com::sun::star::accessibility::AccessibleRole::LABEL);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
571 : : }
572 : :
573 : :
574 : : } } // end of namespace ::sd::toolpanel
575 : :
576 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|