1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/themes/metal.cpp
3 // Purpose: wxUniversal theme implementing Win32-like LNF
4 // Author: Vadim Zeitlin, Robert Roebling
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/univ/theme.h"
35 #include "wx/window.h"
37 #include "wx/dcmemory.h"
39 #include "wx/button.h"
40 #include "wx/listbox.h"
41 #include "wx/checklst.h"
42 #include "wx/combobox.h"
43 #include "wx/scrolbar.h"
44 #include "wx/slider.h"
45 #include "wx/textctrl.h"
46 #include "wx/toolbar.h"
49 #include "wx/settings.h"
50 #include "wx/toplevel.h"
53 #include "wx/notebook.h"
54 #include "wx/spinbutt.h"
55 #include "wx/artprov.h"
57 #include "wx/univ/scrtimer.h"
58 #include "wx/univ/renderer.h"
59 #include "wx/univ/inpcons.h"
60 #include "wx/univ/inphand.h"
61 #include "wx/univ/colschem.h"
63 // wxMetalRenderer: draw the GUI elements in Metal style
64 // ----------------------------------------------------------------------------
66 class wxMetalRenderer
: public wxDelegateRenderer
68 // FIXME cut'n'paste from Win32
84 Arrow_InvertedDisabled
,
88 wxMetalRenderer(wxRenderer
*renderer
, wxColourScheme
* scheme
);
90 virtual void DrawButtonSurface(wxDC
& dc
,
91 const wxColour
& WXUNUSED(col
),
94 { DrawMetal(dc
, rect
); }
96 virtual void DrawScrollbarThumb(wxDC
& dc
,
101 virtual void DrawScrollbarShaft(wxDC
& dc
,
102 wxOrientation orient
,
103 const wxRect
& rectBar
,
106 virtual void GetComboBitmaps(wxBitmap
*bmpNormal
,
108 wxBitmap
*bmpPressed
,
109 wxBitmap
*bmpDisabled
);
111 virtual void DrawArrow(wxDC
& dc
,
116 void DrawArrowButton(wxDC
& dc
,
117 const wxRect
& rectAll
,
118 wxArrowDirection arrowDir
,
119 wxArrowStyle arrowStyle
);
121 void DrawRect(wxDC
& dc
, wxRect
*rect
, const wxPen
& pen
);
123 void DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
124 const wxPen
& pen1
, const wxPen
& pen2
);
126 void DrawArrowBorder(wxDC
& dc
, wxRect
*rect
, bool isPressed
= false);
128 void DrawArrow(wxDC
& dc
, const wxRect
& rect
,
129 wxArrowDirection arrowDir
, wxArrowStyle arrowStyle
);
131 void DrawMetal(wxDC
&dc
, const wxRect
&rect
);
138 wxBitmap m_bmpArrows
[Arrow_StateMax
][Arrow_Max
];
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 class wxMetalTheme
: public wxTheme
149 virtual ~wxMetalTheme();
151 virtual wxRenderer
*GetRenderer();
152 virtual wxArtProvider
*GetArtProvider();
153 virtual wxInputHandler
*GetInputHandler(const wxString
& control
,
154 wxInputConsumer
*consumer
);
155 virtual wxColourScheme
*GetColourScheme();
158 bool GetOrCreateTheme()
161 m_win32Theme
= wxTheme::Create( wxT("win32") );
162 return m_win32Theme
!= NULL
;
165 wxTheme
*m_win32Theme
;
166 wxMetalRenderer
*m_renderer
;
168 WX_DECLARE_THEME(Metal
)
171 // ============================================================================
173 // ============================================================================
175 WX_IMPLEMENT_THEME(wxMetalTheme
, Metal
, wxTRANSLATE("Metal theme"));
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
181 wxMetalTheme::wxMetalTheme()
187 wxMetalTheme::~wxMetalTheme()
193 wxRenderer
*wxMetalTheme::GetRenderer()
195 if ( !GetOrCreateTheme() )
198 m_renderer
= new wxMetalRenderer(m_win32Theme
->GetRenderer(),
199 m_win32Theme
->GetColourScheme());
204 wxArtProvider
*wxMetalTheme::GetArtProvider()
206 if ( !GetOrCreateTheme() )
208 return m_win32Theme
->GetArtProvider();
211 wxInputHandler
*wxMetalTheme::GetInputHandler(const wxString
& control
,
212 wxInputConsumer
*consumer
)
214 if ( !GetOrCreateTheme() )
216 return m_win32Theme
->GetInputHandler(control
, consumer
);
219 wxColourScheme
*wxMetalTheme::GetColourScheme()
221 if ( !GetOrCreateTheme() )
223 return m_win32Theme
->GetColourScheme();
226 // ----------------------------------------------------------------------------
228 // ----------------------------------------------------------------------------
230 wxMetalRenderer::wxMetalRenderer(wxRenderer
*renderer
, wxColourScheme
*scheme
)
231 : wxDelegateRenderer(renderer
)
233 // init colours and pens
234 m_penBlack
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_DARK
), 0, wxSOLID
);
235 m_penDarkGrey
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_OUT
), 0, wxSOLID
);
236 m_penLightGrey
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_IN
), 0, wxSOLID
);
237 m_penHighlight
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_HIGHLIGHT
), 0, wxSOLID
);
239 // init the arrow bitmaps
240 static const size_t ARROW_WIDTH
= 7;
241 static const size_t ARROW_LENGTH
= 4;
247 for ( size_t n
= 0; n
< Arrow_Max
; n
++ )
249 bool isVertical
= n
> Arrow_Right
;
262 // disabled arrow is larger because of the shadow
263 m_bmpArrows
[Arrow_Normal
][n
].Create(w
, h
);
264 m_bmpArrows
[Arrow_Disabled
][n
].Create(w
+ 1, h
+ 1);
266 dcNormal
.SelectObject(m_bmpArrows
[Arrow_Normal
][n
]);
267 dcDisabled
.SelectObject(m_bmpArrows
[Arrow_Disabled
][n
]);
269 dcNormal
.SetBackground(*wxWHITE_BRUSH
);
270 dcDisabled
.SetBackground(*wxWHITE_BRUSH
);
274 dcNormal
.SetPen(m_penBlack
);
275 dcDisabled
.SetPen(m_penDarkGrey
);
277 // calculate the position of the point of the arrow
281 x1
= (ARROW_WIDTH
- 1)/2;
282 y1
= n
== Arrow_Up
? 0 : ARROW_LENGTH
- 1;
286 x1
= n
== Arrow_Left
? 0 : ARROW_LENGTH
- 1;
287 y1
= (ARROW_WIDTH
- 1)/2;
298 for ( size_t i
= 0; i
< ARROW_LENGTH
; i
++ )
300 dcNormal
.DrawLine(x1
, y1
, x2
, y2
);
301 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
319 else // left or right arrow
324 if ( n
== Arrow_Left
)
337 // draw the shadow for the disabled one
338 dcDisabled
.SetPen(m_penHighlight
);
343 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
347 x1
= ARROW_LENGTH
- 1;
348 y1
= (ARROW_WIDTH
- 1)/2 + 1;
351 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
352 dcDisabled
.DrawLine(++x1
, y1
, x2
, ++y2
);
357 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
361 x1
= ARROW_WIDTH
- 1;
363 x2
= (ARROW_WIDTH
- 1)/2;
365 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
366 dcDisabled
.DrawLine(++x1
, y1
, x2
, ++y2
);
371 // create the inverted bitmap but only for the right arrow as we only
372 // use it for the menus
373 if ( n
== Arrow_Right
)
375 m_bmpArrows
[Arrow_Inverted
][n
].Create(w
, h
);
376 dcInverse
.SelectObject(m_bmpArrows
[Arrow_Inverted
][n
]);
378 dcInverse
.Blit(0, 0, w
, h
,
381 dcInverse
.SelectObject(wxNullBitmap
);
383 mask
= new wxMask(m_bmpArrows
[Arrow_Inverted
][n
], *wxBLACK
);
384 m_bmpArrows
[Arrow_Inverted
][n
].SetMask(mask
);
386 m_bmpArrows
[Arrow_InvertedDisabled
][n
].Create(w
, h
);
387 dcInverse
.SelectObject(m_bmpArrows
[Arrow_InvertedDisabled
][n
]);
389 dcInverse
.Blit(0, 0, w
, h
,
392 dcInverse
.SelectObject(wxNullBitmap
);
394 mask
= new wxMask(m_bmpArrows
[Arrow_InvertedDisabled
][n
], *wxBLACK
);
395 m_bmpArrows
[Arrow_InvertedDisabled
][n
].SetMask(mask
);
398 dcNormal
.SelectObject(wxNullBitmap
);
399 dcDisabled
.SelectObject(wxNullBitmap
);
401 mask
= new wxMask(m_bmpArrows
[Arrow_Normal
][n
], *wxWHITE
);
402 m_bmpArrows
[Arrow_Normal
][n
].SetMask(mask
);
403 mask
= new wxMask(m_bmpArrows
[Arrow_Disabled
][n
], *wxWHITE
);
404 m_bmpArrows
[Arrow_Disabled
][n
].SetMask(mask
);
406 m_bmpArrows
[Arrow_Pressed
][n
] = m_bmpArrows
[Arrow_Normal
][n
];
410 void wxMetalRenderer::DrawScrollbarThumb(wxDC
& dc
,
411 wxOrientation
WXUNUSED(orient
),
415 // we don't use the flags, the thumb never changes appearance
416 wxRect rectThumb
= rect
;
417 DrawArrowBorder(dc
, &rectThumb
);
418 DrawMetal(dc
, rectThumb
);
421 void wxMetalRenderer::DrawScrollbarShaft(wxDC
& dc
,
422 wxOrientation
WXUNUSED(orient
),
423 const wxRect
& rectBar
,
426 DrawMetal(dc
, rectBar
);
429 void wxMetalRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
430 wxBitmap
* WXUNUSED(bmpFocus
),
431 wxBitmap
*bmpPressed
,
432 wxBitmap
*bmpDisabled
)
434 static const wxCoord widthCombo
= 16;
435 static const wxCoord heightCombo
= 17;
441 bmpNormal
->Create(widthCombo
, heightCombo
);
442 dcMem
.SelectObject(*bmpNormal
);
443 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
444 Arrow_Down
, Arrow_Normal
);
449 bmpPressed
->Create(widthCombo
, heightCombo
);
450 dcMem
.SelectObject(*bmpPressed
);
451 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
452 Arrow_Down
, Arrow_Pressed
);
457 bmpDisabled
->Create(widthCombo
, heightCombo
);
458 dcMem
.SelectObject(*bmpDisabled
);
459 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
460 Arrow_Down
, Arrow_Disabled
);
464 void wxMetalRenderer::DrawArrow(wxDC
& dc
,
469 // get the bitmap for this arrow
470 wxArrowDirection arrowDir
;
473 case wxLEFT
: arrowDir
= Arrow_Left
; break;
474 case wxRIGHT
: arrowDir
= Arrow_Right
; break;
475 case wxUP
: arrowDir
= Arrow_Up
; break;
476 case wxDOWN
: arrowDir
= Arrow_Down
; break;
479 wxFAIL_MSG(_T("unknown arrow direction"));
483 wxArrowStyle arrowStyle
;
484 if ( flags
& wxCONTROL_PRESSED
)
486 // can't be pressed and disabled
487 arrowStyle
= Arrow_Pressed
;
491 arrowStyle
= flags
& wxCONTROL_DISABLED
? Arrow_Disabled
: Arrow_Normal
;
494 DrawArrowButton(dc
, rect
, arrowDir
, arrowStyle
);
498 // protected functions
501 void wxMetalRenderer::DrawArrowButton(wxDC
& dc
,
502 const wxRect
& rectAll
,
503 wxArrowDirection arrowDir
,
504 wxArrowStyle arrowStyle
)
506 wxRect rect
= rectAll
;
507 DrawMetal( dc
, rect
);
508 DrawArrowBorder(dc
, &rect
, arrowStyle
== Arrow_Pressed
);
509 DrawArrow(dc
, rect
, arrowDir
, arrowStyle
);
512 void wxMetalRenderer::DrawRect(wxDC
& dc
, wxRect
*rect
, const wxPen
& pen
)
516 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
517 dc
.DrawRectangle(*rect
);
523 void wxMetalRenderer::DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
524 const wxPen
& pen1
, const wxPen
& pen2
)
526 // draw the rectangle
528 dc
.DrawLine(rect
->GetLeft(), rect
->GetTop(),
529 rect
->GetLeft(), rect
->GetBottom());
530 dc
.DrawLine(rect
->GetLeft() + 1, rect
->GetTop(),
531 rect
->GetRight(), rect
->GetTop());
533 dc
.DrawLine(rect
->GetRight(), rect
->GetTop(),
534 rect
->GetRight(), rect
->GetBottom());
535 dc
.DrawLine(rect
->GetLeft(), rect
->GetBottom(),
536 rect
->GetRight() + 1, rect
->GetBottom());
542 void wxMetalRenderer::DrawArrowBorder(wxDC
& dc
, wxRect
*rect
, bool isPressed
)
546 DrawRect(dc
, rect
, m_penDarkGrey
);
548 // the arrow is usually drawn inside border of width 2 and is offset by
549 // another pixel in both directions when it's pressed - as the border
550 // in this case is more narrow as well, we have to adjust rect like
558 DrawShadedRect(dc
, rect
, m_penLightGrey
, m_penBlack
);
559 DrawShadedRect(dc
, rect
, m_penHighlight
, m_penDarkGrey
);
563 void wxMetalRenderer::DrawArrow(wxDC
& dc
,
565 wxArrowDirection arrowDir
,
566 wxArrowStyle arrowStyle
)
568 const wxBitmap
& bmp
= m_bmpArrows
[arrowStyle
][arrowDir
];
570 // under Windows the arrows always have the same size so just centre it in
571 // the provided rectangle
572 wxCoord x
= rect
.x
+ (rect
.width
- bmp
.GetWidth()) / 2,
573 y
= rect
.y
+ (rect
.height
- bmp
.GetHeight()) / 2;
575 // Windows does it like this...
576 if ( arrowDir
== Arrow_Left
)
580 dc
.DrawBitmap(bmp
, x
, y
, true /* use mask */);
583 // ----------------------------------------------------------------------------
585 // ----------------------------------------------------------------------------
587 void wxMetalRenderer::DrawMetal(wxDC
&dc
, const wxRect
&rect
)
589 dc
.SetPen(*wxTRANSPARENT_PEN
);
590 for (int y
= rect
.y
; y
< rect
.height
+rect
.y
; y
++)
592 unsigned char intens
= (unsigned char)(230 + 80 * (rect
.y
-y
) / rect
.height
);
593 dc
.SetBrush( wxBrush( wxColour(intens
,intens
,intens
), wxSOLID
) );
594 dc
.DrawRectangle( rect
.x
, y
, rect
.width
, 1 );
598 #endif // wxUSE_THEME_METAL