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 // ----------------------------------------------------------------------------
64 // wxMetalRenderer: draw the GUI elements in Metal style
65 // ----------------------------------------------------------------------------
67 class wxMetalRenderer
: public wxDelegateRenderer
69 // FIXME cut'n'paste from Win32
85 Arrow_InvertedDisabled
,
89 wxMetalRenderer(wxRenderer
*renderer
, wxColourScheme
* scheme
);
91 virtual void DrawButtonSurface(wxDC
& dc
,
92 const wxColour
& WXUNUSED(col
),
95 { DrawMetal(dc
, rect
); }
97 virtual void DrawScrollbarThumb(wxDC
& dc
,
102 virtual void DrawScrollbarShaft(wxDC
& dc
,
103 wxOrientation orient
,
104 const wxRect
& rectBar
,
107 virtual void GetComboBitmaps(wxBitmap
*bmpNormal
,
109 wxBitmap
*bmpPressed
,
110 wxBitmap
*bmpDisabled
);
112 virtual void DrawArrow(wxDC
& dc
,
117 void DrawArrowButton(wxDC
& dc
,
118 const wxRect
& rectAll
,
119 wxArrowDirection arrowDir
,
120 wxArrowStyle arrowStyle
);
122 void DrawRect(wxDC
& dc
, wxRect
*rect
, const wxPen
& pen
);
124 void DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
125 const wxPen
& pen1
, const wxPen
& pen2
);
127 void DrawArrowBorder(wxDC
& dc
, wxRect
*rect
, bool isPressed
= false);
129 void DrawArrow(wxDC
& dc
, const wxRect
& rect
,
130 wxArrowDirection arrowDir
, wxArrowStyle arrowStyle
);
132 void DrawMetal(wxDC
&dc
, const wxRect
&rect
);
139 wxBitmap m_bmpArrows
[Arrow_StateMax
][Arrow_Max
];
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 class wxMetalTheme
: public wxDelegateTheme
149 wxMetalTheme() : wxDelegateTheme(_T("win32")), m_renderer(NULL
) {}
150 ~wxMetalTheme() { delete m_renderer
; }
153 virtual wxRenderer
*GetRenderer()
157 m_renderer
= new wxMetalRenderer(m_theme
->GetRenderer(),
164 wxRenderer
*m_renderer
;
166 WX_DECLARE_THEME(Metal
)
169 WX_IMPLEMENT_THEME(wxMetalTheme
, Metal
, wxTRANSLATE("Metal theme"));
172 // ============================================================================
174 // ============================================================================
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 wxMetalRenderer::wxMetalRenderer(wxRenderer
*renderer
, wxColourScheme
*scheme
)
181 : wxDelegateRenderer(renderer
)
183 // init colours and pens
184 m_penBlack
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_DARK
), 0, wxSOLID
);
185 m_penDarkGrey
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_OUT
), 0, wxSOLID
);
186 m_penLightGrey
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_IN
), 0, wxSOLID
);
187 m_penHighlight
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_HIGHLIGHT
), 0, wxSOLID
);
189 // init the arrow bitmaps
190 static const size_t ARROW_WIDTH
= 7;
191 static const size_t ARROW_LENGTH
= 4;
197 for ( size_t n
= 0; n
< Arrow_Max
; n
++ )
199 bool isVertical
= n
> Arrow_Right
;
212 // disabled arrow is larger because of the shadow
213 m_bmpArrows
[Arrow_Normal
][n
].Create(w
, h
);
214 m_bmpArrows
[Arrow_Disabled
][n
].Create(w
+ 1, h
+ 1);
216 dcNormal
.SelectObject(m_bmpArrows
[Arrow_Normal
][n
]);
217 dcDisabled
.SelectObject(m_bmpArrows
[Arrow_Disabled
][n
]);
219 dcNormal
.SetBackground(*wxWHITE_BRUSH
);
220 dcDisabled
.SetBackground(*wxWHITE_BRUSH
);
224 dcNormal
.SetPen(m_penBlack
);
225 dcDisabled
.SetPen(m_penDarkGrey
);
227 // calculate the position of the point of the arrow
231 x1
= (ARROW_WIDTH
- 1)/2;
232 y1
= n
== Arrow_Up
? 0 : ARROW_LENGTH
- 1;
236 x1
= n
== Arrow_Left
? 0 : ARROW_LENGTH
- 1;
237 y1
= (ARROW_WIDTH
- 1)/2;
248 for ( size_t i
= 0; i
< ARROW_LENGTH
; i
++ )
250 dcNormal
.DrawLine(x1
, y1
, x2
, y2
);
251 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
269 else // left or right arrow
274 if ( n
== Arrow_Left
)
287 // draw the shadow for the disabled one
288 dcDisabled
.SetPen(m_penHighlight
);
293 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
297 x1
= ARROW_LENGTH
- 1;
298 y1
= (ARROW_WIDTH
- 1)/2 + 1;
301 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
302 dcDisabled
.DrawLine(++x1
, y1
, x2
, ++y2
);
307 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
311 x1
= ARROW_WIDTH
- 1;
313 x2
= (ARROW_WIDTH
- 1)/2;
315 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
316 dcDisabled
.DrawLine(++x1
, y1
, x2
, ++y2
);
321 // create the inverted bitmap but only for the right arrow as we only
322 // use it for the menus
323 if ( n
== Arrow_Right
)
325 m_bmpArrows
[Arrow_Inverted
][n
].Create(w
, h
);
326 dcInverse
.SelectObject(m_bmpArrows
[Arrow_Inverted
][n
]);
328 dcInverse
.Blit(0, 0, w
, h
,
331 dcInverse
.SelectObject(wxNullBitmap
);
333 mask
= new wxMask(m_bmpArrows
[Arrow_Inverted
][n
], *wxBLACK
);
334 m_bmpArrows
[Arrow_Inverted
][n
].SetMask(mask
);
336 m_bmpArrows
[Arrow_InvertedDisabled
][n
].Create(w
, h
);
337 dcInverse
.SelectObject(m_bmpArrows
[Arrow_InvertedDisabled
][n
]);
339 dcInverse
.Blit(0, 0, w
, h
,
342 dcInverse
.SelectObject(wxNullBitmap
);
344 mask
= new wxMask(m_bmpArrows
[Arrow_InvertedDisabled
][n
], *wxBLACK
);
345 m_bmpArrows
[Arrow_InvertedDisabled
][n
].SetMask(mask
);
348 dcNormal
.SelectObject(wxNullBitmap
);
349 dcDisabled
.SelectObject(wxNullBitmap
);
351 mask
= new wxMask(m_bmpArrows
[Arrow_Normal
][n
], *wxWHITE
);
352 m_bmpArrows
[Arrow_Normal
][n
].SetMask(mask
);
353 mask
= new wxMask(m_bmpArrows
[Arrow_Disabled
][n
], *wxWHITE
);
354 m_bmpArrows
[Arrow_Disabled
][n
].SetMask(mask
);
356 m_bmpArrows
[Arrow_Pressed
][n
] = m_bmpArrows
[Arrow_Normal
][n
];
360 void wxMetalRenderer::DrawScrollbarThumb(wxDC
& dc
,
361 wxOrientation
WXUNUSED(orient
),
365 // we don't use the flags, the thumb never changes appearance
366 wxRect rectThumb
= rect
;
367 DrawArrowBorder(dc
, &rectThumb
);
368 DrawMetal(dc
, rectThumb
);
371 void wxMetalRenderer::DrawScrollbarShaft(wxDC
& dc
,
372 wxOrientation
WXUNUSED(orient
),
373 const wxRect
& rectBar
,
376 DrawMetal(dc
, rectBar
);
379 void wxMetalRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
380 wxBitmap
* WXUNUSED(bmpFocus
),
381 wxBitmap
*bmpPressed
,
382 wxBitmap
*bmpDisabled
)
384 static const wxCoord widthCombo
= 16;
385 static const wxCoord heightCombo
= 17;
391 bmpNormal
->Create(widthCombo
, heightCombo
);
392 dcMem
.SelectObject(*bmpNormal
);
393 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
394 Arrow_Down
, Arrow_Normal
);
399 bmpPressed
->Create(widthCombo
, heightCombo
);
400 dcMem
.SelectObject(*bmpPressed
);
401 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
402 Arrow_Down
, Arrow_Pressed
);
407 bmpDisabled
->Create(widthCombo
, heightCombo
);
408 dcMem
.SelectObject(*bmpDisabled
);
409 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
410 Arrow_Down
, Arrow_Disabled
);
414 void wxMetalRenderer::DrawArrow(wxDC
& dc
,
419 // get the bitmap for this arrow
420 wxArrowDirection arrowDir
;
423 case wxLEFT
: arrowDir
= Arrow_Left
; break;
424 case wxRIGHT
: arrowDir
= Arrow_Right
; break;
425 case wxUP
: arrowDir
= Arrow_Up
; break;
426 case wxDOWN
: arrowDir
= Arrow_Down
; break;
429 wxFAIL_MSG(_T("unknown arrow direction"));
433 wxArrowStyle arrowStyle
;
434 if ( flags
& wxCONTROL_PRESSED
)
436 // can't be pressed and disabled
437 arrowStyle
= Arrow_Pressed
;
441 arrowStyle
= flags
& wxCONTROL_DISABLED
? Arrow_Disabled
: Arrow_Normal
;
444 DrawArrowButton(dc
, rect
, arrowDir
, arrowStyle
);
448 // protected functions
451 void wxMetalRenderer::DrawArrowButton(wxDC
& dc
,
452 const wxRect
& rectAll
,
453 wxArrowDirection arrowDir
,
454 wxArrowStyle arrowStyle
)
456 wxRect rect
= rectAll
;
457 DrawMetal( dc
, rect
);
458 DrawArrowBorder(dc
, &rect
, arrowStyle
== Arrow_Pressed
);
459 DrawArrow(dc
, rect
, arrowDir
, arrowStyle
);
462 void wxMetalRenderer::DrawRect(wxDC
& dc
, wxRect
*rect
, const wxPen
& pen
)
466 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
467 dc
.DrawRectangle(*rect
);
473 void wxMetalRenderer::DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
474 const wxPen
& pen1
, const wxPen
& pen2
)
476 // draw the rectangle
478 dc
.DrawLine(rect
->GetLeft(), rect
->GetTop(),
479 rect
->GetLeft(), rect
->GetBottom());
480 dc
.DrawLine(rect
->GetLeft() + 1, rect
->GetTop(),
481 rect
->GetRight(), rect
->GetTop());
483 dc
.DrawLine(rect
->GetRight(), rect
->GetTop(),
484 rect
->GetRight(), rect
->GetBottom());
485 dc
.DrawLine(rect
->GetLeft(), rect
->GetBottom(),
486 rect
->GetRight() + 1, rect
->GetBottom());
492 void wxMetalRenderer::DrawArrowBorder(wxDC
& dc
, wxRect
*rect
, bool isPressed
)
496 DrawRect(dc
, rect
, m_penDarkGrey
);
498 // the arrow is usually drawn inside border of width 2 and is offset by
499 // another pixel in both directions when it's pressed - as the border
500 // in this case is more narrow as well, we have to adjust rect like
508 DrawShadedRect(dc
, rect
, m_penLightGrey
, m_penBlack
);
509 DrawShadedRect(dc
, rect
, m_penHighlight
, m_penDarkGrey
);
513 void wxMetalRenderer::DrawArrow(wxDC
& dc
,
515 wxArrowDirection arrowDir
,
516 wxArrowStyle arrowStyle
)
518 const wxBitmap
& bmp
= m_bmpArrows
[arrowStyle
][arrowDir
];
520 // under Windows the arrows always have the same size so just centre it in
521 // the provided rectangle
522 wxCoord x
= rect
.x
+ (rect
.width
- bmp
.GetWidth()) / 2,
523 y
= rect
.y
+ (rect
.height
- bmp
.GetHeight()) / 2;
525 // Windows does it like this...
526 if ( arrowDir
== Arrow_Left
)
530 dc
.DrawBitmap(bmp
, x
, y
, true /* use mask */);
533 // ----------------------------------------------------------------------------
535 // ----------------------------------------------------------------------------
537 void wxMetalRenderer::DrawMetal(wxDC
&dc
, const wxRect
&rect
)
539 dc
.SetPen(*wxTRANSPARENT_PEN
);
540 for (int y
= rect
.y
; y
< rect
.height
+rect
.y
; y
++)
542 unsigned char intens
= (unsigned char)(230 + 80 * (rect
.y
-y
) / rect
.height
);
543 dc
.SetBrush( wxBrush( wxColour(intens
,intens
,intens
), wxSOLID
) );
544 dc
.DrawRectangle( rect
.x
, y
, rect
.width
, 1 );
548 #endif // wxUSE_THEME_METAL