LibreOffice Module vcl (master) 1
decoview.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <vcl/settings.hxx>
21#include <vcl/outdev.hxx>
22#include <vcl/decoview.hxx>
23#include <vcl/window.hxx>
24#include <vcl/ctrl.hxx>
25
26namespace {
27
28tools::Long AdjustRectToSquare( tools::Rectangle &rRect )
29{
30 const tools::Long nWidth = rRect.GetWidth();
31 const tools::Long nHeight = rRect.GetHeight();
32 tools::Long nSide = std::min( nWidth, nHeight );
33
34 if ( nSide && !(nSide & 1) )
35 {
36 // we prefer an odd size
37 --nSide;
38 }
39
40 // Make the rectangle a square
41 rRect.SetSize( Size( nSide, nSide ) );
42
43 // and place it at the center of the original rectangle
44 rRect.Move( (nWidth-nSide)/2, (nHeight-nSide)/2 );
45
46 return nSide;
47}
48
49void ImplDrawSymbol( OutputDevice* pDev, tools::Rectangle nRect, const SymbolType eType )
50{
51 const tools::Long nSide = AdjustRectToSquare( nRect );
52
53 if ( !nSide ) return;
54 if ( nSide==1 )
55 {
56 pDev->DrawPixel( Point( nRect.Left(), nRect.Top() ) );
57 return;
58 }
59
60 // Precalculate some values
61 const tools::Long n2 = nSide/2;
62 const tools::Long n4 = (n2+1)/2;
63 const tools::Long n8 = (n4+1)/2;
64 const tools::Long n16 = (n8+1)/2;
65 const Point aCenter = nRect.Center();
66
67 switch ( eType )
68 {
70 {
71 tools::Polygon arrow(7);
72 arrow.SetPoint( Point( aCenter.X(), nRect.Top()), 0 );
73 arrow.SetPoint( Point( aCenter.X() - n2, nRect.Top() + n2 ), 1 );
74 arrow.SetPoint( Point( aCenter.X() - n8, nRect.Top() + n2 ), 2 );
75 arrow.SetPoint( Point( aCenter.X() - n8, nRect.Bottom()), 3 );
76 arrow.SetPoint( Point( aCenter.X() + n8, nRect.Bottom()), 4 );
77 arrow.SetPoint( Point( aCenter.X() + n8, nRect.Top() + n2 ), 5 );
78 arrow.SetPoint( Point( aCenter.X() + n2, nRect.Top() + n2 ), 6 );
80 pDev->SetLineColor();
81 pDev->DrawPolygon( arrow );
82 pDev->Pop();
83 break;
84 }
85
87 {
88 tools::Polygon arrow(7);
89 arrow.SetPoint( Point( aCenter.X(), nRect.Bottom()), 0 );
90 arrow.SetPoint( Point( aCenter.X() - n2, nRect.Bottom() - n2 ), 1 );
91 arrow.SetPoint( Point( aCenter.X() - n8, nRect.Bottom() - n2 ), 2 );
92 arrow.SetPoint( Point( aCenter.X() - n8, nRect.Top()), 3 );
93 arrow.SetPoint( Point( aCenter.X() + n8, nRect.Top()), 4 );
94 arrow.SetPoint( Point( aCenter.X() + n8, nRect.Bottom() - n2 ), 5 );
95 arrow.SetPoint( Point( aCenter.X() + n2, nRect.Bottom() - n2 ), 6 );
97 pDev->SetLineColor();
98 pDev->DrawPolygon( arrow );
99 pDev->Pop();
100 break;
101 }
102
104 {
105 tools::Polygon arrow(7);
106 arrow.SetPoint( Point( nRect.Left(), aCenter.Y()), 0 );
107 arrow.SetPoint( Point( nRect.Left() + n2, aCenter.Y() - n2 ), 1 );
108 arrow.SetPoint( Point( nRect.Left() + n2, aCenter.Y() - n8 ), 2 );
109 arrow.SetPoint( Point( nRect.Right(), aCenter.Y() - n8 ), 3 );
110 arrow.SetPoint( Point( nRect.Right(), aCenter.Y() + n8 ), 4 );
111 arrow.SetPoint( Point( nRect.Left() + n2, aCenter.Y() + n8 ), 5 );
112 arrow.SetPoint( Point( nRect.Left() + n2, aCenter.Y() + n2 ), 6 );
114 pDev->SetLineColor();
115 pDev->DrawPolygon( arrow );
116 pDev->Pop();
117 break;
118 }
119
121 {
122 tools::Polygon arrow(7);
123 arrow.SetPoint( Point( nRect.Right(), aCenter.Y()), 0 );
124 arrow.SetPoint( Point( nRect.Right() - n2, aCenter.Y() - n2 ), 1 );
125 arrow.SetPoint( Point( nRect.Right() - n2, aCenter.Y() - n8 ), 2 );
126 arrow.SetPoint( Point( nRect.Left(), aCenter.Y() - n8 ), 3 );
127 arrow.SetPoint( Point( nRect.Left(), aCenter.Y() + n8 ), 4 );
128 arrow.SetPoint( Point( nRect.Right() - n2, aCenter.Y() + n8 ), 5 );
129 arrow.SetPoint( Point( nRect.Right() - n2, aCenter.Y() + n2 ), 6 );
131 pDev->SetLineColor();
132 pDev->DrawPolygon( arrow );
133 pDev->Pop();
134 break;
135 }
136
138 {
139 tools::Polygon triangle( 3 );
140 triangle.SetPoint( Point( aCenter.X(), nRect.Top() + n4 ), 0 );
141 triangle.SetPoint( Point( aCenter.X() - n2, nRect.Top() + n4 + n2 ), 1 );
142 triangle.SetPoint( Point( aCenter.X() + n2, nRect.Top() + n4 + n2 ), 2 );
144 pDev->SetLineColor();
145 pDev->DrawPolygon( triangle );
146 pDev->Pop();
147 break;
148 }
149
151 {
152 tools::Polygon triangle( 3 );
153 triangle.SetPoint( Point( aCenter.X(), nRect.Bottom() - n4 ), 0 );
154 triangle.SetPoint( Point( aCenter.X() - n2, nRect.Bottom() - n4 - n2 ), 1 );
155 triangle.SetPoint( Point( aCenter.X() + n2, nRect.Bottom() - n4 - n2 ), 2 );
157 pDev->SetLineColor();
158 pDev->DrawPolygon( triangle );
159 pDev->Pop();
160 break;
161 }
162
165 case SymbolType::PREV:
166 {
167 nRect.AdjustLeft(n4 );
168 if ( eType==SymbolType::FIRST )
169 {
170 pDev->DrawLine( Point( nRect.Left(), nRect.Top() ),
171 Point( nRect.Left(), nRect.Bottom() ) );
172 nRect.AdjustLeft( 1 );
173 }
174
175 tools::Polygon aTriangle(3);
176 aTriangle.SetPoint(Point(nRect.Left() + n2, aCenter.Y() - n2), 0);
177 aTriangle.SetPoint(Point(nRect.Left(), aCenter.Y()), 1);
178 aTriangle.SetPoint(Point(nRect.Left() + n2, aCenter.Y() + n2), 2);
179
181 pDev->SetLineColor();
182 pDev->DrawPolygon(aTriangle);
183 pDev->Pop();
184
185 break;
186 }
187
189 case SymbolType::LAST:
190 case SymbolType::NEXT:
191 case SymbolType::PLAY:
192 {
193 nRect.AdjustRight( -n4 );
194 if ( eType==SymbolType::LAST )
195 {
196 pDev->DrawLine( Point( nRect.Right(), nRect.Top() ),
197 Point( nRect.Right(), nRect.Bottom() ) );
198 nRect.AdjustRight( -1 );
199 }
200
201 tools::Polygon aTriangle(3);
202 aTriangle.SetPoint(Point(nRect.Right() - n2, aCenter.Y() - n2), 0);
203 aTriangle.SetPoint(Point(nRect.Right(), aCenter.Y()), 1);
204 aTriangle.SetPoint(Point(nRect.Right() - n2, aCenter.Y() + n2), 2);
205
207 pDev->SetLineColor();
208 pDev->DrawPolygon(aTriangle);
209 pDev->Pop();
210 break;
211 }
212
214 {
215 tools::Polygon triangle( 3 );
216 triangle.SetPoint( Point( aCenter.X(), nRect.Top()), 0 );
217 triangle.SetPoint( Point( aCenter.X() - n2, nRect.Top() + n2 ), 1 );
218 triangle.SetPoint( Point( aCenter.X() + n2, nRect.Top() + n2 ), 2 );
220 pDev->SetLineColor();
221 pDev->DrawPolygon( triangle );
222 triangle.Move( 0, n2 );
223 pDev->DrawPolygon( triangle );
224 pDev->Pop();
225 break;
226 }
227
229 {
230 tools::Polygon triangle( 3 );
231 triangle.SetPoint( Point( aCenter.X(), nRect.Bottom()), 0 );
232 triangle.SetPoint( Point( aCenter.X() - n2, nRect.Bottom() - n2 ), 1 );
233 triangle.SetPoint( Point( aCenter.X() + n2, nRect.Bottom() - n2 ), 2 );
235 pDev->SetLineColor();
236 pDev->DrawPolygon( triangle );
237 triangle.Move( 0, -n2 );
238 pDev->DrawPolygon( triangle );
239 pDev->Pop();
240 break;
241 }
242
244 {
245 pDev->DrawEllipse(nRect);
246 break;
247 }
248
249 case SymbolType::STOP:
250 pDev->DrawRect( nRect );
251 break;
252
254 {
255 const tools::Long diff = std::max<tools::Long>( 0, n8 - 1 );
256 tools::Polygon cross( 16 );
257 cross.SetPoint( Point( nRect.Left(), nRect.Top()), 0 );
258 cross.SetPoint( Point( nRect.Left(), nRect.Top() + diff ), 1 );
259 cross.SetPoint( Point( aCenter.X() - diff, aCenter.Y()), 2 );
260 cross.SetPoint( Point( nRect.Left(), nRect.Bottom() - diff ), 3 );
261 cross.SetPoint( Point( nRect.Left(), nRect.Bottom()), 4 );
262 cross.SetPoint( Point( nRect.Left() + diff, nRect.Bottom()), 5 );
263 cross.SetPoint( Point( aCenter.X(), aCenter.Y() + diff ), 6 );
264 cross.SetPoint( Point( nRect.Right() - diff, nRect.Bottom()), 7 );
265 cross.SetPoint( Point( nRect.Right(), nRect.Bottom()), 8 );
266 cross.SetPoint( Point( nRect.Right(), nRect.Bottom() - diff ), 9 );
267 cross.SetPoint( Point( aCenter.X() + diff, aCenter.Y()), 10 );
268 cross.SetPoint( Point( nRect.Right(), nRect.Top() + diff ), 11 );
269 cross.SetPoint( Point( nRect.Right(), nRect.Top()), 12 );
270 cross.SetPoint( Point( nRect.Right() - diff, nRect.Top()), 13 );
271 cross.SetPoint( Point( aCenter.X(), aCenter.Y() - diff ), 14 );
272 cross.SetPoint( Point( nRect.Left() + diff, nRect.Top()), 15 );
273 pDev->DrawPolygon( cross );
274 break;
275 }
276
278 {
279 tools::Long n3 = nSide/3;
280 nRect.AdjustTop( -(n3/2) );
281 nRect.AdjustBottom( -(n3/2) );
282 tools::Polygon checkmark(6);
283 // #106953# never mirror checkmarks
284 if ( pDev->HasMirroredGraphics() && pDev->IsRTLEnabled() )
285 {
286 // Draw a mirrored checkmark so that it looks "normal" in a
287 // mirrored graphics device (double mirroring!)
288 checkmark.SetPoint( Point( nRect.Right(), nRect.Bottom()-n3 ), 0 );
289 checkmark.SetPoint( Point( nRect.Right()-n3, nRect.Bottom()), 1 );
290 checkmark.SetPoint( Point( nRect.Left(), nRect.Top()+n3 ), 2 );
291 checkmark.SetPoint( Point( nRect.Left(), nRect.Top()+n3 + 1 ), 3 );
292 checkmark.SetPoint( Point( nRect.Right()-n3, nRect.Bottom() + 1 ), 4 );
293 checkmark.SetPoint( Point( nRect.Right(), nRect.Bottom()-n3 + 1 ), 5 );
294 }
295 else
296 {
297 checkmark.SetPoint( Point( nRect.Left(), nRect.Bottom()-n3 ), 0 );
298 checkmark.SetPoint( Point( nRect.Left()+n3, nRect.Bottom()), 1 );
299 checkmark.SetPoint( Point( nRect.Right(), nRect.Top()+n3 ), 2 );
300 checkmark.SetPoint( Point( nRect.Right(), nRect.Top()+n3 + 1 ), 3 );
301 checkmark.SetPoint( Point( nRect.Left()+n3, nRect.Bottom() + 1 ), 4 );
302 checkmark.SetPoint( Point( nRect.Left(), nRect.Bottom()-n3 + 1 ), 5 );
303 }
304 pDev->DrawPolygon( checkmark );
305 }
306 break;
307
309 nRect.AdjustRight( -n4 );
310 nRect.AdjustTop(n4+1 );
311 pDev->DrawRect( tools::Rectangle( nRect.Left(), nRect.Top(),
312 nRect.Right(), nRect.Top()+n8 ) );
313 pDev->DrawLine( Point( nRect.Left(), nRect.Top()+n8 ),
314 Point( nRect.Left(), nRect.Bottom() ) );
315 pDev->DrawLine( Point( nRect.Left(), nRect.Bottom() ),
316 Point( nRect.Right(), nRect.Bottom() ) );
317 pDev->DrawLine( Point( nRect.Right(), nRect.Top()+n8 ),
318 Point( nRect.Right(), nRect.Bottom() ) );
319 nRect.AdjustRight(n4 );
320 nRect.AdjustTop( -(n4+1) );
321 nRect.AdjustLeft(n4 );
322 nRect.AdjustBottom( -(n4+1) );
323 pDev->DrawRect( tools::Rectangle( nRect.Left(), nRect.Top(),
324 nRect.Right(), nRect.Top()+n8 ) );
325 pDev->DrawLine( Point( nRect.Left(), nRect.Top()+n8 ),
326 Point( nRect.Left(), nRect.Bottom() ) );
327 pDev->DrawLine( Point( nRect.Left(), nRect.Bottom() ),
328 Point( nRect.Right(), nRect.Bottom() ) );
329 pDev->DrawLine( Point( nRect.Right(), nRect.Top()+n8 ),
330 Point( nRect.Right(), nRect.Bottom() ) );
331 break;
332
333 case SymbolType::DOCK:
334 pDev->DrawLine( Point( nRect.Left(), nRect.Top() ),
335 Point( nRect.Right(), nRect.Top() ) );
336 pDev->DrawLine( Point( nRect.Left(), nRect.Top() ),
337 Point( nRect.Left(), nRect.Bottom() ) );
338 pDev->DrawLine( Point( nRect.Left(), nRect.Bottom() ),
339 Point( nRect.Right(), nRect.Bottom() ) );
340 pDev->DrawLine( Point( nRect.Right(), nRect.Top() ),
341 Point( nRect.Right(), nRect.Bottom() ) );
342 break;
343
344 case SymbolType::HIDE:
345 pDev->DrawRect( tools::Rectangle( nRect.Left()+n8, nRect.Bottom()-n8,
346 nRect.Right()-n8, nRect.Bottom() ) );
347 break;
348
349 case SymbolType::PLUS:
350 pDev->DrawRect( tools::Rectangle( nRect.Left(), aCenter.Y()-n16,
351 nRect.Right(), aCenter.Y()+n16 ) );
352 pDev->DrawRect( tools::Rectangle( aCenter.X()-n16, nRect.Top(),
353 aCenter.X()+n16, nRect.Bottom() ) );
354 break;
357 case SymbolType::HELP: break;
358 }
359}
360
361void ImplDrawDPILineRect( OutputDevice *const pDev, tools::Rectangle& rRect,
362 const Color *const pColor, const bool bRound = false )
363{
364 tools::Long nLineWidth = pDev->GetDPIX()/300;
365 tools::Long nLineHeight = pDev->GetDPIY()/300;
366 if ( !nLineWidth )
367 nLineWidth = 1;
368 if ( !nLineHeight )
369 nLineHeight = 1;
370
371 if ( pColor )
372 {
373 if ( (nLineWidth == 1) && (nLineHeight == 1) )
374 {
375 pDev->SetLineColor( *pColor );
376 if( bRound )
377 {
378 pDev->DrawLine( Point( rRect.Left()+1, rRect.Top()), Point( rRect.Right()-1, rRect.Top()) );
379 pDev->DrawLine( Point( rRect.Left()+1, rRect.Bottom()), Point( rRect.Right()-1, rRect.Bottom()) );
380 pDev->DrawLine( Point( rRect.Left(), rRect.Top()+1), Point( rRect.Left(), rRect.Bottom()-1) );
381 pDev->DrawLine( Point( rRect.Right(), rRect.Top()+1), Point( rRect.Right(), rRect.Bottom()-1) );
382 }
383 else
384 {
385 pDev->SetFillColor();
386 pDev->DrawRect( rRect );
387 }
388 }
389 else
390 {
391 const tools::Long nWidth = rRect.GetWidth();
392 const tools::Long nHeight = rRect.GetHeight();
393 pDev->SetLineColor();
394 pDev->SetFillColor( *pColor );
395 pDev->DrawRect( tools::Rectangle( rRect.TopLeft(), Size( nWidth, nLineHeight ) ) );
396 pDev->DrawRect( tools::Rectangle( rRect.TopLeft(), Size( nLineWidth, nHeight ) ) );
397 pDev->DrawRect( tools::Rectangle( Point( rRect.Left(), rRect.Bottom()-nLineHeight ),
398 Size( nWidth, nLineHeight ) ) );
399 pDev->DrawRect( tools::Rectangle( Point( rRect.Right()-nLineWidth, rRect.Top() ),
400 Size( nLineWidth, nHeight ) ) );
401 }
402 }
403
404 rRect.AdjustLeft(nLineWidth );
405 rRect.AdjustTop(nLineHeight );
406 rRect.AdjustRight( -nLineWidth );
407 rRect.AdjustBottom( -nLineHeight );
408}
409
410void ImplDraw2ColorFrame( OutputDevice *const pDev, tools::Rectangle& rRect,
411 const Color& rLeftTopColor, const Color& rRightBottomColor )
412{
413 pDev->SetLineColor( rLeftTopColor );
414 pDev->DrawLine( rRect.TopLeft(), rRect.BottomLeft() );
415 pDev->DrawLine( rRect.TopLeft(), rRect.TopRight() );
416 pDev->SetLineColor( rRightBottomColor );
417 pDev->DrawLine( rRect.BottomLeft(), rRect.BottomRight() );
418 pDev->DrawLine( rRect.TopRight(), rRect.BottomRight() );
419
420 // reduce drawing area
421 rRect.AdjustLeft( 1 );
422 rRect.AdjustTop( 1 );
423 rRect.AdjustRight( -1 );
424 rRect.AdjustBottom( -1 );
425}
426
427void ImplDrawButton( OutputDevice *const pDev, tools::Rectangle aFillRect,
428 const DrawButtonFlags nStyle )
429{
430 const StyleSettings& rStyleSettings = pDev->GetSettings().GetStyleSettings();
431
432 if ( (nStyle & DrawButtonFlags::Mono) ||
433 (rStyleSettings.GetOptions() & StyleSettingsOptions::Mono) )
434 {
435 const Color aBlackColor(COL_BLACK);
436
437 if ( nStyle & DrawButtonFlags::Default )
438 {
439 // default selection shows a wider border
440 ImplDrawDPILineRect( pDev, aFillRect, &aBlackColor );
441 }
442
443 ImplDrawDPILineRect( pDev, aFillRect, &aBlackColor );
444
445 Size aBrdSize(pDev->GetButtonBorderSize());
446
447 pDev->SetLineColor();
448 pDev->SetFillColor( aBlackColor );
449 const tools::Rectangle aOrigFillRect(aFillRect);
451 {
452 // shrink fill rect
453 aFillRect.AdjustLeft(aBrdSize.Width() );
454 aFillRect.AdjustTop(aBrdSize.Height() );
455 // draw top and left borders (aOrigFillRect-aFillRect)
456 pDev->DrawRect( tools::Rectangle( aOrigFillRect.Left(), aOrigFillRect.Top(),
457 aOrigFillRect.Right(), aFillRect.Top()-1 ) );
458 pDev->DrawRect( tools::Rectangle( aOrigFillRect.Left(), aOrigFillRect.Top(),
459 aFillRect.Left()-1, aOrigFillRect.Bottom() ) );
460 }
461 else
462 {
463 // shrink fill rect
464 aFillRect.AdjustRight( -(aBrdSize.Width()) );
465 aFillRect.AdjustBottom( -(aBrdSize.Height()) );
466 // draw bottom and right borders (aOrigFillRect-aFillRect)
467 pDev->DrawRect( tools::Rectangle( aOrigFillRect.Left(), aFillRect.Bottom()+1,
468 aOrigFillRect.Right(), aOrigFillRect.Bottom() ) );
469 pDev->DrawRect( tools::Rectangle( aFillRect.Right()+1, aOrigFillRect.Top(),
470 aOrigFillRect.Right(), aOrigFillRect.Bottom() ) );
471 }
472
473 // Hack: in monochrome mode on printers we like to have grey buttons
475 pDev->DrawRect( aFillRect );
476 }
477 else
478 {
479 const bool bFlat(nStyle & DrawButtonFlags::Flat);
480 const bool bDepressed(nStyle & (DrawButtonFlags::Pressed | DrawButtonFlags::Checked));
481
482 if ( nStyle & DrawButtonFlags::Default )
483 {
484 const Color aDefBtnColor = rStyleSettings.GetDarkShadowColor();
485 ImplDrawDPILineRect( pDev, aFillRect, &aDefBtnColor );
486 }
487
489 {
490 pDev->SetLineColor( rStyleSettings.GetLightBorderColor() );
491 pDev->DrawLine( Point( aFillRect.Left(), aFillRect.Top() ),
492 Point( aFillRect.Left(), aFillRect.Bottom() ) );
493 aFillRect.AdjustLeft( 1 );
494 }
495
496 bool bNoFace = false;
497 Color aColor1;
498 Color aColor2;
499 if (!bFlat)
500 {
501 if (bDepressed)
502 {
503 aColor1 = rStyleSettings.GetDarkShadowColor();
504 aColor2 = rStyleSettings.GetLightColor();
505 }
506 else
507 {
508 if ( nStyle & DrawButtonFlags::NoLightBorder )
509 aColor1 = rStyleSettings.GetLightBorderColor();
510 else
511 aColor1 = rStyleSettings.GetLightColor();
512 aColor2 = rStyleSettings.GetDarkShadowColor();
513 }
514
515 ImplDraw2ColorFrame( pDev, aFillRect, aColor1, aColor2 );
516
517 if (bDepressed)
518 {
519 aColor1 = rStyleSettings.GetShadowColor();
520 aColor2 = rStyleSettings.GetLightBorderColor();
521 }
522 else
523 {
524 if ( nStyle & DrawButtonFlags::NoLightBorder )
525 aColor1 = rStyleSettings.GetLightColor();
526 else
527 aColor1 = rStyleSettings.GetLightBorderColor();
528 aColor2 = rStyleSettings.GetShadowColor();
529 }
530 ImplDraw2ColorFrame( pDev, aFillRect, aColor1, aColor2 );
531 }
532 else // flat buttons
533 {
534 // draw a border if the flat button is highlighted
535 if (nStyle & DrawButtonFlags::Highlight)
536 {
537 aColor1 = rStyleSettings.GetShadowColor();
538 ImplDraw2ColorFrame(pDev, aFillRect, aColor1, aColor1);
539 }
540 // fill in the button if it is pressed in
541 bNoFace = !bDepressed;
542 }
543
544 pDev->SetLineColor();
546 pDev->SetFillColor( rStyleSettings.GetCheckedColor() );
547 else if (!bNoFace)
548 pDev->SetFillColor( rStyleSettings.GetFaceColor() );
549 pDev->DrawRect( aFillRect );
550 }
551}
552
553void ImplDrawFrame( OutputDevice *const pDev, tools::Rectangle& rRect,
554 const StyleSettings& rStyleSettings, DrawFrameStyle nStyle, DrawFrameFlags nFlags )
555{
556 vcl::Window * pWin = pDev->GetOwnerWindow();
557
558 const bool bMenuStyle(nFlags & DrawFrameFlags::Menu);
559
560 // UseFlatBorders disables 3D style for all frames except menus
561 // menus may use different border colors (eg on XP)
562 // normal frames will be drawn using the shadow color
563 // whereas window frame borders will use black
564 bool bFlatBorders = !bMenuStyle && rStyleSettings.GetUseFlatBorders();
565
566 // no flat borders for standard VCL controls (ie formcontrols that keep their classic look)
567 // will not affect frame windows (like dropdowns)
568 if( bFlatBorders && pWin && pWin->GetType() == WindowType::BORDERWINDOW && (pWin != pWin->ImplGetFrameWindow()) )
569 {
570 // check for formcontrol, i.e., a control without NWF enabled
571 Control *const pControl = dynamic_cast< Control* >( pWin->GetWindow( GetWindowType::Client ) );
572 if( !pControl || !pControl->IsNativeWidgetEnabled() )
573 bFlatBorders = false;
574 }
575
576 const bool bNoDraw(nFlags & DrawFrameFlags::NoDraw);
577
578 if ( (rStyleSettings.GetOptions() & StyleSettingsOptions::Mono) ||
579 (pDev->GetOutDevType() == OUTDEV_PRINTER) ||
580 bFlatBorders )
581 nFlags |= DrawFrameFlags::Mono;
582
583 if( nStyle != DrawFrameStyle::NWF &&
585 {
586 tools::Long nControlFlags = static_cast<tools::Long>(nStyle);
587 nControlFlags |= static_cast<tools::Long>(nFlags);
588 nControlFlags |= static_cast<tools::Long>(pWin->GetType() == WindowType::BORDERWINDOW ?
590 ImplControlValue aControlValue( nControlFlags );
591
592 tools::Rectangle aBound, aContent;
593 tools::Rectangle aNatRgn( rRect );
595 aNatRgn, ControlState::NONE, aControlValue, aBound, aContent) )
596 {
597 // if bNoDraw is true then don't call the drawing routine
598 // but just update the target rectangle
599 if( bNoDraw ||
601 aControlValue, OUString()) )
602 {
603 rRect = aContent;
604 return;
605 }
606 }
607 }
608
609 if ( nFlags & DrawFrameFlags::Mono )
610 {
611 // no round corners for window frame borders
612 const bool bRound = bFlatBorders && !(nFlags & DrawFrameFlags::WindowBorder);
613
614 if ( bNoDraw )
615 {
616 ImplDrawDPILineRect( pDev, rRect, nullptr, bRound );
617 }
618 else
619 {
620 Color aColor = bRound ? rStyleSettings.GetShadowColor()
622 // when the MonoColor wasn't set, check face color
623 if (
624 (bRound && aColor.IsDark()) ||
625 (
626 (aColor == COL_BLACK) &&
628 )
629 )
630 {
631 aColor = COL_WHITE;
632 }
633 ImplDrawDPILineRect( pDev, rRect, &aColor, bRound );
634 }
635 }
636 else
637 {
638 if ( bNoDraw )
639 {
640 switch ( nStyle )
641 {
644 rRect.AdjustLeft( 1 );
645 rRect.AdjustTop( 1 );
646 rRect.AdjustRight( -1 );
647 rRect.AdjustBottom( -1 );
648 break;
649
653 rRect.AdjustLeft(2 );
654 rRect.AdjustTop(2 );
655 rRect.AdjustRight( -2 );
656 rRect.AdjustBottom( -2 );
657 break;
658
660 // enough space for the native rendering
661 rRect.AdjustLeft(4 );
662 rRect.AdjustTop(4 );
663 rRect.AdjustRight( -4 );
664 rRect.AdjustBottom( -4 );
665 break;
666 default: break;
667 }
668 }
669 else
670 {
671 switch ( nStyle )
672 {
674 pDev->SetFillColor();
675 pDev->SetLineColor( rStyleSettings.GetLightColor() );
676 pDev->DrawRect( tools::Rectangle( rRect.Left()+1, rRect.Top()+1,
677 rRect.Right(), rRect.Bottom() ) );
678 pDev->SetLineColor( rStyleSettings.GetShadowColor() );
679 pDev->DrawRect( tools::Rectangle( rRect.Left(), rRect.Top(),
680 rRect.Right()-1, rRect.Bottom()-1 ) );
681
682 // adjust target rectangle
683 rRect.AdjustLeft(2 );
684 rRect.AdjustTop(2 );
685 rRect.AdjustRight( -2 );
686 rRect.AdjustBottom( -2 );
687 break;
688
690 ImplDraw2ColorFrame( pDev, rRect,
691 rStyleSettings.GetShadowColor(),
692 rStyleSettings.GetLightColor() );
693 break;
694
696 ImplDraw2ColorFrame( pDev, rRect,
697 rStyleSettings.GetLightColor(),
698 rStyleSettings.GetShadowColor() );
699 break;
700
702 if( bFlatBorders )
703 {
704 // no 3d effect
705 ImplDraw2ColorFrame( pDev, rRect,
706 rStyleSettings.GetShadowColor(),
707 rStyleSettings.GetShadowColor() );
708 ImplDraw2ColorFrame( pDev, rRect,
709 rStyleSettings.GetFaceColor(),
710 rStyleSettings.GetFaceColor() );
711 }
712 else
713 {
714 ImplDraw2ColorFrame( pDev, rRect,
715 rStyleSettings.GetShadowColor(),
716 rStyleSettings.GetLightColor() );
717 ImplDraw2ColorFrame( pDev, rRect,
718 rStyleSettings.GetDarkShadowColor(),
719 rStyleSettings.GetLightBorderColor() );
720 }
721 break;
722
724 if( bMenuStyle )
725 {
726 ImplDraw2ColorFrame( pDev, rRect,
727 rStyleSettings.GetMenuBorderColor(),
728 rStyleSettings.GetDarkShadowColor() );
729 if ( !rStyleSettings.GetUseFlatMenus() )
730 {
731 ImplDraw2ColorFrame( pDev, rRect,
732 rStyleSettings.GetLightColor(),
733 rStyleSettings.GetShadowColor() );
734 }
735 }
736 else
737 {
738 ImplDraw2ColorFrame( pDev, rRect,
739 bFlatBorders ? // no 3d effect
740 rStyleSettings.GetDarkShadowColor() :
741 rStyleSettings.GetLightBorderColor(),
742 rStyleSettings.GetDarkShadowColor() );
743 ImplDraw2ColorFrame( pDev, rRect,
744 rStyleSettings.GetLightColor(),
745 rStyleSettings.GetShadowColor() );
746 }
747 break;
748
750 // no rendering, just enough space for the native rendering
751 rRect.AdjustLeft(4 );
752 rRect.AdjustTop(4 );
753 rRect.AdjustRight( -4 );
754 rRect.AdjustBottom( -4 );
755 break;
756 default: break;
757 }
758 }
759 }
760}
761
762} // end anonymous namespace
763
765 mpOutDev(pOutDev)
766{}
767
769 const Color& rColor, DrawSymbolFlags nStyle )
770{
771 const StyleSettings& rStyleSettings = mpOutDev->GetSettings().GetStyleSettings();
772 const tools::Rectangle aRect = mpOutDev->LogicToPixel( rRect );
773 const Color aOldLineColor = mpOutDev->GetLineColor();
774 const Color aOldFillColor = mpOutDev->GetFillColor();
775 const bool bOldMapMode = mpOutDev->IsMapModeEnabled();
776 Color nColor(rColor);
777 mpOutDev->EnableMapMode( false );
778
779 if ( (rStyleSettings.GetOptions() & StyleSettingsOptions::Mono) ||
781 nStyle |= DrawSymbolFlags::Mono;
782
783 if ( nStyle & DrawSymbolFlags::Mono )
784 {
785 // Monochrome: set color to black if enabled, to gray if disabled
786 nColor = ( nStyle & DrawSymbolFlags::Disable ) ? COL_GRAY : COL_BLACK;
787 }
788 else
789 {
790 if ( nStyle & DrawSymbolFlags::Disable )
791 {
792 // Draw shifted and brighter symbol for embossed look
793 mpOutDev->SetLineColor( rStyleSettings.GetLightColor() );
794 mpOutDev->SetFillColor( rStyleSettings.GetLightColor() );
795 ImplDrawSymbol( mpOutDev, aRect + Point(1, 1) , eType );
796 nColor = rStyleSettings.GetShadowColor();
797 }
798 }
799
800 // Set selected color and draw the symbol
801 mpOutDev->SetLineColor( nColor );
802 mpOutDev->SetFillColor( nColor );
803 ImplDrawSymbol( mpOutDev, aRect, eType );
804
805 // Restore previous settings
806 mpOutDev->SetLineColor( aOldLineColor );
807 mpOutDev->SetFillColor( aOldFillColor );
808 mpOutDev->EnableMapMode( bOldMapMode );
809}
810
812 const Color& rLeftTopColor,
813 const Color& rRightBottomColor )
814{
815 tools::Rectangle aRect = mpOutDev->LogicToPixel( rRect );
816 const Color aOldLineColor = mpOutDev->GetLineColor();
817 const bool bOldMapMode = mpOutDev->IsMapModeEnabled();
818 mpOutDev->EnableMapMode( false );
819 ImplDraw2ColorFrame( mpOutDev, aRect, rLeftTopColor, rRightBottomColor );
820 mpOutDev->SetLineColor( aOldLineColor );
821 mpOutDev->EnableMapMode( bOldMapMode );
822}
823
826{
827 const StyleSettings& rStyleSettings = mpOutDev->GetSettings().GetStyleSettings();
828 Color aLightColor = rStyleSettings.GetLightColor();
829 Color aShadowColor = rStyleSettings.GetShadowColor();
830
831 if ( (rStyleSettings.GetOptions() & StyleSettingsOptions::Mono) ||
833 {
834 aLightColor = COL_BLACK;
835 aShadowColor = COL_BLACK;
836 }
837 else
838 {
839 Wallpaper aBackground = mpOutDev->GetBackground();
840 if ( aBackground.IsBitmap() || aBackground.IsGradient() )
841 {
842 aLightColor = rStyleSettings.GetFaceColor();
843 aShadowColor = COL_BLACK;
844 }
845 else
846 {
847 Color aBackColor = aBackground.GetColor();
848 if ( (aLightColor.GetColorError( aBackColor ) < 96) ||
849 (aShadowColor.GetColorError( aBackColor ) < 96) )
850 {
851 aLightColor = COL_WHITE;
852 aShadowColor = COL_BLACK;
853
854 if ( aLightColor.GetColorError( aBackColor ) < 96 )
855 aLightColor.DecreaseLuminance( 64 );
856 if ( aShadowColor.GetColorError( aBackColor ) < 96 )
857 aShadowColor.IncreaseLuminance( 64 );
858 }
859 }
860 }
861
862 if ( nStyle == DrawHighlightFrameStyle::In )
863 std::swap( aLightColor, aShadowColor );
864
865 DrawFrame( rRect, aLightColor, aShadowColor );
866}
867
869{
870 tools::Rectangle aRect = mpOutDev->LogicToPixel( rRect );
871 bool bOldMap = mpOutDev->IsMapModeEnabled();
872 mpOutDev->EnableMapMode( false );
873
874 if ( !rRect.IsEmpty() )
875 {
876 if ( nFlags & DrawFrameFlags::NoDraw )
877 ImplDrawFrame( mpOutDev, aRect, mpOutDev->GetSettings().GetStyleSettings(), nStyle, nFlags );
878 else
879 {
880 Color aOldLineColor = mpOutDev->GetLineColor();
881 Color aOldFillColor = mpOutDev->GetFillColor();
882 ImplDrawFrame( mpOutDev, aRect, mpOutDev->GetSettings().GetStyleSettings(), nStyle, nFlags );
883 mpOutDev->SetLineColor( aOldLineColor );
884 mpOutDev->SetFillColor( aOldFillColor );
885 }
886 }
887
888 mpOutDev->EnableMapMode( bOldMap );
889 aRect = mpOutDev->PixelToLogic( aRect );
890
891 return aRect;
892}
893
895{
896 if ( rRect.IsEmpty() )
897 {
898 return rRect;
899 }
900
901 tools::Rectangle aRect = mpOutDev->LogicToPixel( rRect );
902 const bool bOldMap = mpOutDev->IsMapModeEnabled();
903 mpOutDev->EnableMapMode( false );
904
905 const Color aOldLineColor = mpOutDev->GetLineColor();
906 const Color aOldFillColor = mpOutDev->GetFillColor();
907 ImplDrawButton( mpOutDev, aRect, nStyle );
908 mpOutDev->SetLineColor( aOldLineColor );
909 mpOutDev->SetFillColor( aOldFillColor );
910
911 // keep border free, although it is used at default representation
912 aRect.AdjustLeft( 1 );
913 aRect.AdjustTop( 1 );
914 aRect.AdjustRight( -1 );
915 aRect.AdjustBottom( -1 );
916
917 if ( nStyle & DrawButtonFlags::NoLightBorder )
918 {
919 aRect.AdjustLeft( 1 );
920 aRect.AdjustTop( 1 );
921 }
922 else if ( nStyle & DrawButtonFlags::NoLeftLightBorder )
923 {
924 aRect.AdjustLeft( 1 );
925 }
926
927 if ( nStyle & DrawButtonFlags::Pressed )
928 {
929 if ( (aRect.GetHeight() > 10) && (aRect.GetWidth() > 10) )
930 {
931 aRect.AdjustLeft(4 );
932 aRect.AdjustTop(4 );
933 aRect.AdjustRight( -1 );
934 aRect.AdjustBottom( -1 );
935 }
936 else
937 {
938 aRect.AdjustLeft(3 );
939 aRect.AdjustTop(3 );
940 aRect.AdjustRight( -2 );
941 aRect.AdjustBottom( -2 );
942 }
943 }
944 else if ( nStyle & DrawButtonFlags::Checked )
945 {
946 aRect.AdjustLeft(3 );
947 aRect.AdjustTop(3 );
948 aRect.AdjustRight( -2 );
949 aRect.AdjustBottom( -2 );
950 }
951 else
952 {
953 aRect.AdjustLeft(2 );
954 aRect.AdjustTop(2 );
955 aRect.AdjustRight( -3 );
956 aRect.AdjustBottom( -3 );
957 }
958
959 mpOutDev->EnableMapMode( bOldMap );
960 aRect = mpOutDev->PixelToLogic( aRect );
961
962 return aRect;
963}
964
965void DecorationView::DrawSeparator( const Point& rStart, const Point& rStop, bool bVertical )
966{
967 Point aStart( rStart ), aStop( rStop );
968 const StyleSettings& rStyleSettings = mpOutDev->GetSettings().GetStyleSettings();
969 vcl::Window *const pWin = mpOutDev->GetOwnerWindow();
970 if(pWin)
971 {
973 bool nativeSupported = pWin->IsNativeControlSupported( ControlType::Fixedline, nPart );
974 ImplControlValue aValue;
975 tools::Rectangle aRect(rStart,rStop);
976 if(nativeSupported && pWin->GetOutDev()->DrawNativeControl(ControlType::Fixedline,nPart,aRect,ControlState::NONE,aValue,OUString()))
977 return;
978 }
979
981 if ( rStyleSettings.GetOptions() & StyleSettingsOptions::Mono )
983 else
984 mpOutDev->SetLineColor( rStyleSettings.GetSeparatorColor() );
985
986 mpOutDev->DrawLine( aStart, aStop );
987
988 mpOutDev->Pop();
989}
990
992{
993 const StyleSettings& rStyleSettings = mpOutDev->GetSettings().GetStyleSettings();
994
995 Size aOutputSize = rRect.GetSize();
996
997 mpOutDev->SetLineColor(rStyleSettings.GetDarkShadowColor());
998 mpOutDev->SetFillColor(rStyleSettings.GetDarkShadowColor());
999
1000 const sal_Int32 nNumberOfPoints = 3;
1001
1002 tools::Long nHalfWidth = aOutputSize.Width() / 2.0f;
1003
1004 float fDistance = aOutputSize.Height();
1005 fDistance /= (nNumberOfPoints + 1);
1006
1007 tools::Long nRadius = aOutputSize.Width();
1008 nRadius /= (nNumberOfPoints + 2);
1009
1010 for (tools::Long i = 1; i <= nNumberOfPoints; i++)
1011 {
1012 tools::Rectangle aLocation(nHalfWidth - nRadius,
1013 round(fDistance * i) - nRadius,
1014 nHalfWidth + nRadius,
1015 round(fDistance * i) + nRadius);
1016 mpOutDev->DrawEllipse(aLocation);
1017 }
1018}
1019
1020/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nLineWidth
const StyleSettings & GetStyleSettings() const
void DecreaseLuminance(sal_uInt8 cLumDec)
bool IsDark() const
void IncreaseLuminance(sal_uInt8 cLumInc)
sal_uInt16 GetColorError(const Color &rCompareColor) const
Definition: ctrl.hxx:80
tools::Rectangle DrawButton(const tools::Rectangle &rRect, DrawButtonFlags nStyle)
Definition: decoview.cxx:894
void DrawHandle(const tools::Rectangle &rRectangle)
Definition: decoview.cxx:991
void DrawSymbol(const tools::Rectangle &rRect, SymbolType eType, const Color &rColor, DrawSymbolFlags nStyle=DrawSymbolFlags::NONE)
Definition: decoview.cxx:768
void DrawHighlightFrame(const tools::Rectangle &rRect, DrawHighlightFrameStyle nStyle)
Definition: decoview.cxx:824
VclPtr< OutputDevice > mpOutDev
Definition: decoview.hxx:75
void DrawFrame(const tools::Rectangle &rRect, const Color &rLeftTopColor, const Color &rRightBottomColor)
Definition: decoview.cxx:811
void DrawSeparator(const Point &rStart, const Point &rStop, bool bVertical=true)
Definition: decoview.cxx:965
DecorationView(OutputDevice *pOutDev)
Definition: decoview.cxx:764
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:170
SAL_DLLPRIVATE sal_Int32 GetDPIX() const
Get the output device's DPI x-axis value.
Definition: outdev.hxx:385
void EnableMapMode(bool bEnable=true)
Definition: map.cxx:589
void DrawEllipse(const tools::Rectangle &rRect)
SAL_DLLPRIVATE sal_Int32 GetDPIY() const
Get the output device's DPI y-axis value.
Definition: outdev.hxx:391
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1110
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:50
void DrawLine(const Point &rStartPt, const Point &rEndPt)
Definition: line.cxx:161
const Wallpaper & GetBackground() const
Definition: outdev.hxx:523
void SetLineColor()
Definition: line.cxx:37
void DrawPolygon(const tools::Polygon &rPoly)
Render the given polygon.
Definition: polygon.cxx:154
void DrawPixel(const Point &rPt)
Definition: pixel.cxx:54
bool IsRTLEnabled() const
Definition: outdev.hxx:1269
void SetFillColor()
Definition: fill.cxx:29
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:879
virtual Size GetButtonBorderSize()
Definition: outdev.hxx:421
virtual bool HasMirroredGraphics() const
Definition: outdev.cxx:703
const Color & GetLineColor() const
Definition: outdev.hxx:510
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
Definition: stack.cxx:32
void Pop()
Definition: stack.cxx:91
bool DrawNativeControl(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, const OUString &aCaption, const Color &rBackgroundColor=COL_AUTO)
Request rendering of a particular control and/or part.
OutDevType GetOutDevType() const
Definition: outdev.hxx:406
virtual Color GetMonochromeButtonColor()
Definition: outdev.hxx:422
const AllSettings & GetSettings() const
Definition: outdev.hxx:288
virtual vcl::Window * GetOwnerWindow() const
Get the vcl::Window that this OutputDevice belongs to, if any.
Definition: outdev.hxx:1897
bool IsMapModeEnabled() const
Definition: outdev.hxx:1551
const Color & GetFillColor() const
Definition: outdev.hxx:515
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const Color & GetMonoColor() const
const Color & GetDarkShadowColor() const
const Color & GetShadowColor() const
StyleSettingsOptions GetOptions() const
Color GetSeparatorColor() const
const Color & GetCheckedColor() const
const Color & GetLightBorderColor() const
bool GetUseFlatMenus() const
const Color & GetLightColor() const
bool GetUseFlatBorders() const
const Color & GetFaceColor() const
const Color & GetMenuBorderColor() const
const Color & GetColor() const
Definition: wall.hxx:71
bool IsBitmap() const
Definition: wall.cxx:189
bool IsGradient() const
Definition: wall.cxx:213
constexpr Point Center() const
constexpr tools::Long GetWidth() const
constexpr tools::Long Top() const
void SetSize(const Size &)
constexpr Point TopLeft() const
constexpr Size GetSize() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
constexpr tools::Long Right() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
constexpr Point BottomRight() const
constexpr Point TopRight() const
constexpr tools::Long GetHeight() const
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
constexpr bool IsEmpty() const
constexpr Point BottomLeft() const
bool IsNativeWidgetEnabled() const
Definition: window.cxx:3710
WindowType GetType() const
Definition: window2.cxx:1000
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1036
bool GetNativeControlRegion(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, tools::Rectangle &rNativeBoundingRegion, tools::Rectangle &rNativeContentRegion) const
Query the native control's actual drawing region (including adornment)
Definition: window3.cxx:79
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
Definition: window3.cxx:74
::OutputDevice const * GetOutDev() const
Definition: window.cxx:567
SAL_DLLPRIVATE vcl::Window * ImplGetFrameWindow() const
Definition: window2.cxx:937
constexpr ::Color COL_GRAY(0x80, 0x80, 0x80)
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
DrawButtonFlags
Definition: decoview.hxx:54
DrawHighlightFrameStyle
Definition: decoview.hxx:47
DrawSymbolFlags
Definition: decoview.hxx:35
DocumentType eType
int n2
sal_uInt32 n4
sal_uInt32 n3
B3DVector cross(const B3DVector &rVecA, const B3DVector &rVecB)
int i
long Long
@ OUTDEV_PRINTER
Definition: outdev.hxx:145
SymbolType
Definition: vclenum.hxx:74
DrawFrameStyle
Definition: vclenum.hxx:290
DrawFrameFlags
Definition: vclenum.hxx:302