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 #include "wx/settings.h"
46 #include "wx/toplevel.h"
49 #include "wx/notebook.h"
50 #include "wx/spinbutt.h"
51 #include "wx/artprov.h"
53 #include "wx/univ/scrtimer.h"
54 #include "wx/univ/renderer.h"
55 #include "wx/univ/inpcons.h"
56 #include "wx/univ/inphand.h"
57 #include "wx/univ/colschem.h"
58 #include "wx/univ/theme.h"
60 // wxMetalRenderer: draw the GUI elements in Metal style
61 // ----------------------------------------------------------------------------
63 class wxMetalRenderer
: public wxDelegateRenderer
65 // FIXME cut'n'paste from Win32
81 Arrow_InvertedDisabled
,
85 wxMetalRenderer(wxRenderer
*renderer
, wxColourScheme
* scheme
);
87 virtual void DrawButtonSurface(wxDC
& dc
,
88 const wxColour
& WXUNUSED(col
),
91 { DrawMetal(dc
, rect
); }
93 virtual void DrawScrollbarThumb(wxDC
& dc
,
98 virtual void DrawScrollbarShaft(wxDC
& dc
,
100 const wxRect
& rectBar
,
103 virtual void GetComboBitmaps(wxBitmap
*bmpNormal
,
105 wxBitmap
*bmpPressed
,
106 wxBitmap
*bmpDisabled
);
108 virtual void DrawArrow(wxDC
& dc
,
113 void DrawArrowButton(wxDC
& dc
,
114 const wxRect
& rectAll
,
115 wxArrowDirection arrowDir
,
116 wxArrowStyle arrowStyle
);
118 void DrawRect(wxDC
& dc
, wxRect
*rect
, const wxPen
& pen
);
120 void DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
121 const wxPen
& pen1
, const wxPen
& pen2
);
123 void DrawArrowBorder(wxDC
& dc
, wxRect
*rect
, bool isPressed
= false);
125 void DrawArrow(wxDC
& dc
, const wxRect
& rect
,
126 wxArrowDirection arrowDir
, wxArrowStyle arrowStyle
);
128 void DrawMetal(wxDC
&dc
, const wxRect
&rect
);
135 wxBitmap m_bmpArrows
[Arrow_StateMax
][Arrow_Max
];
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 class wxMetalTheme
: public wxTheme
146 virtual ~wxMetalTheme();
148 virtual wxRenderer
*GetRenderer();
149 virtual wxArtProvider
*GetArtProvider();
150 virtual wxInputHandler
*GetInputHandler(const wxString
& control
,
151 wxInputConsumer
*consumer
);
152 virtual wxColourScheme
*GetColourScheme();
155 bool GetOrCreateTheme()
158 m_win32Theme
= wxTheme::Create( wxT("win32") );
159 return m_win32Theme
!= NULL
;
162 wxTheme
*m_win32Theme
;
163 wxMetalRenderer
*m_renderer
;
165 WX_DECLARE_THEME(Metal
)
168 // ============================================================================
170 // ============================================================================
172 WX_IMPLEMENT_THEME(wxMetalTheme
, Metal
, wxTRANSLATE("Metal theme"));
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 wxMetalTheme::wxMetalTheme()
184 wxMetalTheme::~wxMetalTheme()
190 wxRenderer
*wxMetalTheme::GetRenderer()
192 if ( !GetOrCreateTheme() )
195 m_renderer
= new wxMetalRenderer(m_win32Theme
->GetRenderer(),
196 m_win32Theme
->GetColourScheme());
201 wxArtProvider
*wxMetalTheme::GetArtProvider()
203 if ( !GetOrCreateTheme() )
205 return m_win32Theme
->GetArtProvider();
208 wxInputHandler
*wxMetalTheme::GetInputHandler(const wxString
& control
,
209 wxInputConsumer
*consumer
)
211 if ( !GetOrCreateTheme() )
213 return m_win32Theme
->GetInputHandler(control
, consumer
);
216 wxColourScheme
*wxMetalTheme::GetColourScheme()
218 if ( !GetOrCreateTheme() )
220 return m_win32Theme
->GetColourScheme();
223 // ----------------------------------------------------------------------------
225 // ----------------------------------------------------------------------------
227 wxMetalRenderer::wxMetalRenderer(wxRenderer
*renderer
, wxColourScheme
*scheme
)
228 : wxDelegateRenderer(renderer
)
230 // init colours and pens
231 m_penBlack
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_DARK
), 0, wxSOLID
);
232 m_penDarkGrey
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_OUT
), 0, wxSOLID
);
233 m_penLightGrey
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_IN
), 0, wxSOLID
);
234 m_penHighlight
= wxPen(wxSCHEME_COLOUR(scheme
, SHADOW_HIGHLIGHT
), 0, wxSOLID
);
236 // init the arrow bitmaps
237 static const size_t ARROW_WIDTH
= 7;
238 static const size_t ARROW_LENGTH
= 4;
244 for ( size_t n
= 0; n
< Arrow_Max
; n
++ )
246 bool isVertical
= n
> Arrow_Right
;
259 // disabled arrow is larger because of the shadow
260 m_bmpArrows
[Arrow_Normal
][n
].Create(w
, h
);
261 m_bmpArrows
[Arrow_Disabled
][n
].Create(w
+ 1, h
+ 1);
263 dcNormal
.SelectObject(m_bmpArrows
[Arrow_Normal
][n
]);
264 dcDisabled
.SelectObject(m_bmpArrows
[Arrow_Disabled
][n
]);
266 dcNormal
.SetBackground(*wxWHITE_BRUSH
);
267 dcDisabled
.SetBackground(*wxWHITE_BRUSH
);
271 dcNormal
.SetPen(m_penBlack
);
272 dcDisabled
.SetPen(m_penDarkGrey
);
274 // calculate the position of the point of the arrow
278 x1
= (ARROW_WIDTH
- 1)/2;
279 y1
= n
== Arrow_Up
? 0 : ARROW_LENGTH
- 1;
283 x1
= n
== Arrow_Left
? 0 : ARROW_LENGTH
- 1;
284 y1
= (ARROW_WIDTH
- 1)/2;
295 for ( size_t i
= 0; i
< ARROW_LENGTH
; i
++ )
297 dcNormal
.DrawLine(x1
, y1
, x2
, y2
);
298 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
316 else // left or right arrow
321 if ( n
== Arrow_Left
)
334 // draw the shadow for the disabled one
335 dcDisabled
.SetPen(m_penHighlight
);
340 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
344 x1
= ARROW_LENGTH
- 1;
345 y1
= (ARROW_WIDTH
- 1)/2 + 1;
348 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
349 dcDisabled
.DrawLine(++x1
, y1
, x2
, ++y2
);
354 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
358 x1
= ARROW_WIDTH
- 1;
360 x2
= (ARROW_WIDTH
- 1)/2;
362 dcDisabled
.DrawLine(x1
, y1
, x2
, y2
);
363 dcDisabled
.DrawLine(++x1
, y1
, x2
, ++y2
);
368 // create the inverted bitmap but only for the right arrow as we only
369 // use it for the menus
370 if ( n
== Arrow_Right
)
372 m_bmpArrows
[Arrow_Inverted
][n
].Create(w
, h
);
373 dcInverse
.SelectObject(m_bmpArrows
[Arrow_Inverted
][n
]);
375 dcInverse
.Blit(0, 0, w
, h
,
378 dcInverse
.SelectObject(wxNullBitmap
);
380 mask
= new wxMask(m_bmpArrows
[Arrow_Inverted
][n
], *wxBLACK
);
381 m_bmpArrows
[Arrow_Inverted
][n
].SetMask(mask
);
383 m_bmpArrows
[Arrow_InvertedDisabled
][n
].Create(w
, h
);
384 dcInverse
.SelectObject(m_bmpArrows
[Arrow_InvertedDisabled
][n
]);
386 dcInverse
.Blit(0, 0, w
, h
,
389 dcInverse
.SelectObject(wxNullBitmap
);
391 mask
= new wxMask(m_bmpArrows
[Arrow_InvertedDisabled
][n
], *wxBLACK
);
392 m_bmpArrows
[Arrow_InvertedDisabled
][n
].SetMask(mask
);
395 dcNormal
.SelectObject(wxNullBitmap
);
396 dcDisabled
.SelectObject(wxNullBitmap
);
398 mask
= new wxMask(m_bmpArrows
[Arrow_Normal
][n
], *wxWHITE
);
399 m_bmpArrows
[Arrow_Normal
][n
].SetMask(mask
);
400 mask
= new wxMask(m_bmpArrows
[Arrow_Disabled
][n
], *wxWHITE
);
401 m_bmpArrows
[Arrow_Disabled
][n
].SetMask(mask
);
403 m_bmpArrows
[Arrow_Pressed
][n
] = m_bmpArrows
[Arrow_Normal
][n
];
407 void wxMetalRenderer::DrawScrollbarThumb(wxDC
& dc
,
408 wxOrientation
WXUNUSED(orient
),
412 // we don't use the flags, the thumb never changes appearance
413 wxRect rectThumb
= rect
;
414 DrawArrowBorder(dc
, &rectThumb
);
415 DrawMetal(dc
, rectThumb
);
418 void wxMetalRenderer::DrawScrollbarShaft(wxDC
& dc
,
419 wxOrientation
WXUNUSED(orient
),
420 const wxRect
& rectBar
,
423 DrawMetal(dc
, rectBar
);
426 void wxMetalRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
427 wxBitmap
* WXUNUSED(bmpFocus
),
428 wxBitmap
*bmpPressed
,
429 wxBitmap
*bmpDisabled
)
431 static const wxCoord widthCombo
= 16;
432 static const wxCoord heightCombo
= 17;
438 bmpNormal
->Create(widthCombo
, heightCombo
);
439 dcMem
.SelectObject(*bmpNormal
);
440 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
441 Arrow_Down
, Arrow_Normal
);
446 bmpPressed
->Create(widthCombo
, heightCombo
);
447 dcMem
.SelectObject(*bmpPressed
);
448 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
449 Arrow_Down
, Arrow_Pressed
);
454 bmpDisabled
->Create(widthCombo
, heightCombo
);
455 dcMem
.SelectObject(*bmpDisabled
);
456 DrawArrowButton(dcMem
, wxRect(0, 0, widthCombo
, heightCombo
),
457 Arrow_Down
, Arrow_Disabled
);
461 void wxMetalRenderer::DrawArrow(wxDC
& dc
,
466 // get the bitmap for this arrow
467 wxArrowDirection arrowDir
;
470 case wxLEFT
: arrowDir
= Arrow_Left
; break;
471 case wxRIGHT
: arrowDir
= Arrow_Right
; break;
472 case wxUP
: arrowDir
= Arrow_Up
; break;
473 case wxDOWN
: arrowDir
= Arrow_Down
; break;
476 wxFAIL_MSG(_T("unknown arrow direction"));
480 wxArrowStyle arrowStyle
;
481 if ( flags
& wxCONTROL_PRESSED
)
483 // can't be pressed and disabled
484 arrowStyle
= Arrow_Pressed
;
488 arrowStyle
= flags
& wxCONTROL_DISABLED
? Arrow_Disabled
: Arrow_Normal
;
491 DrawArrowButton(dc
, rect
, arrowDir
, arrowStyle
);
495 // protected functions
498 void wxMetalRenderer::DrawArrowButton(wxDC
& dc
,
499 const wxRect
& rectAll
,
500 wxArrowDirection arrowDir
,
501 wxArrowStyle arrowStyle
)
503 wxRect rect
= rectAll
;
504 DrawMetal( dc
, rect
);
505 DrawArrowBorder(dc
, &rect
, arrowStyle
== Arrow_Pressed
);
506 DrawArrow(dc
, rect
, arrowDir
, arrowStyle
);
509 void wxMetalRenderer::DrawRect(wxDC
& dc
, wxRect
*rect
, const wxPen
& pen
)
513 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
514 dc
.DrawRectangle(*rect
);
520 void wxMetalRenderer::DrawShadedRect(wxDC
& dc
, wxRect
*rect
,
521 const wxPen
& pen1
, const wxPen
& pen2
)
523 // draw the rectangle
525 dc
.DrawLine(rect
->GetLeft(), rect
->GetTop(),
526 rect
->GetLeft(), rect
->GetBottom());
527 dc
.DrawLine(rect
->GetLeft() + 1, rect
->GetTop(),
528 rect
->GetRight(), rect
->GetTop());
530 dc
.DrawLine(rect
->GetRight(), rect
->GetTop(),
531 rect
->GetRight(), rect
->GetBottom());
532 dc
.DrawLine(rect
->GetLeft(), rect
->GetBottom(),
533 rect
->GetRight() + 1, rect
->GetBottom());
539 void wxMetalRenderer::DrawArrowBorder(wxDC
& dc
, wxRect
*rect
, bool isPressed
)
543 DrawRect(dc
, rect
, m_penDarkGrey
);
545 // the arrow is usually drawn inside border of width 2 and is offset by
546 // another pixel in both directions when it's pressed - as the border
547 // in this case is more narrow as well, we have to adjust rect like
555 DrawShadedRect(dc
, rect
, m_penLightGrey
, m_penBlack
);
556 DrawShadedRect(dc
, rect
, m_penHighlight
, m_penDarkGrey
);
560 void wxMetalRenderer::DrawArrow(wxDC
& dc
,
562 wxArrowDirection arrowDir
,
563 wxArrowStyle arrowStyle
)
565 const wxBitmap
& bmp
= m_bmpArrows
[arrowStyle
][arrowDir
];
567 // under Windows the arrows always have the same size so just centre it in
568 // the provided rectangle
569 wxCoord x
= rect
.x
+ (rect
.width
- bmp
.GetWidth()) / 2,
570 y
= rect
.y
+ (rect
.height
- bmp
.GetHeight()) / 2;
572 // Windows does it like this...
573 if ( arrowDir
== Arrow_Left
)
577 dc
.DrawBitmap(bmp
, x
, y
, true /* use mask */);
580 // ----------------------------------------------------------------------------
582 // ----------------------------------------------------------------------------
584 void wxMetalRenderer::DrawMetal(wxDC
&dc
, const wxRect
&rect
)
586 dc
.SetPen(*wxTRANSPARENT_PEN
);
587 for (int y
= rect
.y
; y
< rect
.height
+rect
.y
; y
++)
589 unsigned char intens
= (unsigned char)(230 + 80 * (rect
.y
-y
) / rect
.height
);
590 dc
.SetBrush( wxBrush( wxColour(intens
,intens
,intens
), wxSOLID
) );
591 dc
.DrawRectangle( rect
.x
, y
, rect
.width
, 1 );