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"
31 #include "wx/window.h"
33 #include "wx/dcmemory.h"
35 #include "wx/button.h"
36 #include "wx/listbox.h"
37 #include "wx/checklst.h"
38 #include "wx/combobox.h"
39 #include "wx/scrolbar.h"
40 #include "wx/slider.h"
41 #include "wx/textctrl.h"
42 #include "wx/toolbar.h"
45 // for COLOR_* constants
46 #include "wx/msw/private.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/inphand.h"
60 #include "wx/univ/colschem.h"
61 #include "wx/univ/theme.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 WX_DEFINE_ARRAY_PTR(wxInputHandler
*, wxArrayHandlers
);
147 class wxMetalTheme
: public wxTheme
151 virtual ~wxMetalTheme();
153 virtual wxRenderer
*GetRenderer();
154 virtual wxArtProvider
*GetArtProvider();
155 virtual wxInputHandler
*GetInputHandler(const wxString
& control
);
156 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
)
213 if ( !GetOrCreateTheme() )
215 return m_win32Theme
->GetInputHandler(control
);
218 wxColourScheme
*wxMetalTheme::GetColourScheme()
220 if ( !GetOrCreateTheme() )
222 return m_win32Theme
->GetColourScheme();
225 // ----------------------------------------------------------------------------
227 // ----------------------------------------------------------------------------
229 wxMetalRenderer::wxMetalRenderer(wxRenderer
*renderer
, wxColourScheme
*scheme
)
230 : wxDelegateRenderer(renderer
)
232 // init colours and pens
233 m_penBlack
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_DARK
), 0, wxSOLID
);
234 m_penDarkGrey
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_OUT
), 0, wxSOLID
);
235 m_penLightGrey
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_IN
), 0, wxSOLID
);
236 m_penHighlight
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_HIGHLIGHT
), 0, wxSOLID
);
238 // init the arrow bitmaps
239 static const size_t ARROW_WIDTH
= 7;
240 static const size_t ARROW_LENGTH
= 4;
246 for ( size_t n
= 0; n
< Arrow_Max
; n
++ )
248 bool isVertical
= n
> Arrow_Right
;
261 // disabled arrow is larger because of the shadow
262 m_bmpArrows
[Arrow_Normal
][n
].Create(w
, h
);
263 m_bmpArrows
[Arrow_Disabled
][n
].Create(w
+ 1, h
+ 1);
265 dcNormal
.SelectObject(m_bmpArrows
[Arrow_Normal
][n
]);
266 dcDisabled
.SelectObject(m_bmpArrows
[Arrow_Disabled
][n
]);
268 dcNormal
.SetBackground(*wxWHITE_BRUSH
);
269 dcDisabled
.SetBackground(*wxWHITE_BRUSH
);
273 dcNormal
.SetPen(m_penBlack
);
274 dcDisabled
.SetPen(m_penDarkGrey
);
276 // calculate the position of the point of the arrow
280 x1
= (ARROW_WIDTH
- 1)/2;
281 y1
= n
== Arrow_Up
? 0 : ARROW_LENGTH
- 1;
285 x1
= n
== Arrow_Left
? 0 : ARROW_LENGTH
- 1;
286 y1
= (ARROW_WIDTH
- 1)/2;
297 for ( size_t i
= 0; i
< ARROW_LENGTH
; i
++ )
299 dcNormal
.DrawLine(x1
, y1
, x2
, y2
);
300 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
318 else // left or right arrow
323 if ( n
== Arrow_Left
)
336 // draw the shadow for the disabled one
337 dcDisabled
.SetPen(m_penHighlight
);
342 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
346 x1
= ARROW_LENGTH
- 1;
347 y1
= (ARROW_WIDTH
- 1)/2 + 1;
350 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
351 dcDisabled
.DrawLine(++x1
, y1
, x2
, ++y2
);
356 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
360 x1
= ARROW_WIDTH
- 1;
362 x2
= (ARROW_WIDTH
- 1)/2;
364 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
365 dcDisabled
.DrawLine(++x1
, y1
, x2
, ++y2
);
370 // create the inverted bitmap but only for the right arrow as we only
371 // use it for the menus
372 if ( n
== Arrow_Right
)
374 m_bmpArrows
[Arrow_Inverted
][n
].Create(w
, h
);
375 dcInverse
.SelectObject(m_bmpArrows
[Arrow_Inverted
][n
]);
377 dcInverse
.Blit(0, 0, w
, h
,
380 dcInverse
.SelectObject(wxNullBitmap
);
382 mask
= new wxMask(m_bmpArrows
[Arrow_Inverted
][n
], *wxBLACK
);
383 m_bmpArrows
[Arrow_Inverted
][n
].SetMask(mask
);
385 m_bmpArrows
[Arrow_InvertedDisabled
][n
].Create(w
, h
);
386 dcInverse
.SelectObject(m_bmpArrows
[Arrow_InvertedDisabled
][n
]);
388 dcInverse
.Blit(0, 0, w
, h
,
391 dcInverse
.SelectObject(wxNullBitmap
);
393 mask
= new wxMask(m_bmpArrows
[Arrow_InvertedDisabled
][n
], *wxBLACK
);
394 m_bmpArrows
[Arrow_InvertedDisabled
][n
].SetMask(mask
);
397 dcNormal
.SelectObject(wxNullBitmap
);
398 dcDisabled
.SelectObject(wxNullBitmap
);
400 mask
= new wxMask(m_bmpArrows
[Arrow_Normal
][n
], *wxWHITE
);
401 m_bmpArrows
[Arrow_Normal
][n
].SetMask(mask
);
402 mask
= new wxMask(m_bmpArrows
[Arrow_Disabled
][n
], *wxWHITE
);
403 m_bmpArrows
[Arrow_Disabled
][n
].SetMask(mask
);
405 m_bmpArrows
[Arrow_Pressed
][n
] = m_bmpArrows
[Arrow_Normal
][n
];
409 void wxMetalRenderer::DrawScrollbarThumb(wxDC
& dc
,
410 wxOrientation
WXUNUSED(orient
),
414 // we don't use the flags, the thumb never changes appearance
415 wxRect rectThumb
= rect
;
416 DrawArrowBorder(dc
, &rectThumb
);
417 DrawMetal(dc
, rectThumb
);
420 void wxMetalRenderer::DrawScrollbarShaft(wxDC
& dc
,
421 wxOrientation
WXUNUSED(orient
),
422 const wxRect
& rectBar
,
425 DrawMetal(dc
, rectBar
);
428 void wxMetalRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
429 wxBitmap
* WXUNUSED(bmpFocus
),
430 wxBitmap
*bmpPressed
,
431 wxBitmap
*bmpDisabled
)
433 static const wxCoord widthCombo
= 16;
434 static const wxCoord heightCombo
= 17;
440 bmpNormal
->Create(widthCombo
, heightCombo
);
441 dcMem
.SelectObject(*bmpNormal
);
442 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
443 Arrow_Down
, Arrow_Normal
);
448 bmpPressed
->Create(widthCombo
, heightCombo
);
449 dcMem
.SelectObject(*bmpPressed
);
450 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
451 Arrow_Down
, Arrow_Pressed
);
456 bmpDisabled
->Create(widthCombo
, heightCombo
);
457 dcMem
.SelectObject(*bmpDisabled
);
458 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
459 Arrow_Down
, Arrow_Disabled
);
463 void wxMetalRenderer::DrawArrow(wxDC
& dc
,
468 // get the bitmap for this arrow
469 wxArrowDirection arrowDir
;
472 case wxLEFT
: arrowDir
= Arrow_Left
; break;
473 case wxRIGHT
: arrowDir
= Arrow_Right
; break;
474 case wxUP
: arrowDir
= Arrow_Up
; break;
475 case wxDOWN
: arrowDir
= Arrow_Down
; break;
478 wxFAIL_MSG(_T("unknown arrow direction"));
482 wxArrowStyle arrowStyle
;
483 if ( flags
& wxCONTROL_PRESSED
)
485 // can't be pressed and disabled
486 arrowStyle
= Arrow_Pressed
;
490 arrowStyle
= flags
& wxCONTROL_DISABLED
? Arrow_Disabled
: Arrow_Normal
;
493 DrawArrowButton(dc
, rect
, arrowDir
, arrowStyle
);
497 // protected functions
500 void wxMetalRenderer::DrawArrowButton(wxDC
& dc
,
501 const wxRect
& rectAll
,
502 wxArrowDirection arrowDir
,
503 wxArrowStyle arrowStyle
)
505 wxRect rect
= rectAll
;
506 DrawMetal( dc
, rect
);
507 DrawArrowBorder(dc
, &rect
, arrowStyle
== Arrow_Pressed
);
508 DrawArrow(dc
, rect
, arrowDir
, arrowStyle
);
511 void wxMetalRenderer::DrawRect(wxDC
& dc
, wxRect
*rect
, const wxPen
& pen
)
515 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
516 dc
.DrawRectangle(*rect
);
522 void wxMetalRenderer::DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
523 const wxPen
& pen1
, const wxPen
& pen2
)
525 // draw the rectangle
527 dc
.DrawLine(rect
->GetLeft(), rect
->GetTop(),
528 rect
->GetLeft(), rect
->GetBottom());
529 dc
.DrawLine(rect
->GetLeft() + 1, rect
->GetTop(),
530 rect
->GetRight(), rect
->GetTop());
532 dc
.DrawLine(rect
->GetRight(), rect
->GetTop(),
533 rect
->GetRight(), rect
->GetBottom());
534 dc
.DrawLine(rect
->GetLeft(), rect
->GetBottom(),
535 rect
->GetRight() + 1, rect
->GetBottom());
541 void wxMetalRenderer::DrawArrowBorder(wxDC
& dc
, wxRect
*rect
, bool isPressed
)
545 DrawRect(dc
, rect
, m_penDarkGrey
);
547 // the arrow is usually drawn inside border of width 2 and is offset by
548 // another pixel in both directions when it's pressed - as the border
549 // in this case is more narrow as well, we have to adjust rect like
557 DrawShadedRect(dc
, rect
, m_penLightGrey
, m_penBlack
);
558 DrawShadedRect(dc
, rect
, m_penHighlight
, m_penDarkGrey
);
562 void wxMetalRenderer::DrawArrow(wxDC
& dc
,
564 wxArrowDirection arrowDir
,
565 wxArrowStyle arrowStyle
)
567 const wxBitmap
& bmp
= m_bmpArrows
[arrowStyle
][arrowDir
];
569 // under Windows the arrows always have the same size so just centre it in
570 // the provided rectangle
571 wxCoord x
= rect
.x
+ (rect
.width
- bmp
.GetWidth()) / 2,
572 y
= rect
.y
+ (rect
.height
- bmp
.GetHeight()) / 2;
574 // Windows does it like this...
575 if ( arrowDir
== Arrow_Left
)
579 dc
.DrawBitmap(bmp
, x
, y
, true /* use mask */);
582 // ----------------------------------------------------------------------------
584 // ----------------------------------------------------------------------------
586 void wxMetalRenderer::DrawMetal(wxDC
&dc
, const wxRect
&rect
)
588 dc
.SetPen(*wxTRANSPARENT_PEN
);
589 for (int y
= rect
.y
; y
< rect
.height
+rect
.y
; y
++)
591 unsigned char intens
= (unsigned char)(230 + 80 * (rect
.y
-y
) / rect
.height
);
592 dc
.SetBrush( wxBrush( wxColour(intens
,intens
,intens
), wxSOLID
) );
593 dc
.DrawRectangle( rect
.x
, y
, rect
.width
, 1 );