1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/themes/mono.cpp
3 // Purpose: wxUniversal theme for monochrome displays
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2006 REA Elektronik GmbH
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/artprov.h"
32 #include "wx/univ/stdrend.h"
33 #include "wx/univ/inphand.h"
34 #include "wx/univ/colschem.h"
35 #include "wx/univ/theme.h"
37 class wxMonoColourScheme
;
39 #define wxMONO_BG_COL (*wxWHITE)
40 #define wxMONO_FG_COL (*wxBLACK)
42 // ----------------------------------------------------------------------------
43 // wxMonoRenderer: draw the GUI elements in simplest possible way
44 // ----------------------------------------------------------------------------
46 // Warning: many of the methods here are not implemented, the code won't work
47 // if any but a few wxUSE_XXXs are on
48 class wxMonoRenderer
: public wxStdRenderer
51 wxMonoRenderer(const wxColourScheme
*scheme
);
53 virtual void DrawButtonLabel(wxDC
& dc
,
54 const wxString
& label
,
55 const wxBitmap
& image
,
58 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
60 wxRect
*rectBounds
= NULL
);
62 virtual void DrawButtonBorder(wxDC
& dc
,
65 wxRect
*rectIn
= NULL
);
67 virtual void DrawHorizontalLine(wxDC
& dc
,
68 wxCoord y
, wxCoord x1
, wxCoord x2
);
70 virtual void DrawVerticalLine(wxDC
& dc
,
71 wxCoord x
, wxCoord y1
, wxCoord y2
);
73 virtual void DrawArrow(wxDC
& dc
,
77 virtual void DrawScrollbarThumb(wxDC
& dc
,
81 virtual void DrawScrollbarShaft(wxDC
& dc
,
87 virtual void DrawToolBarButton(wxDC
& dc
,
88 const wxString
& label
,
89 const wxBitmap
& bitmap
,
94 #endif // wxUSE_TOOLBAR
97 virtual void DrawTab(wxDC
& dc
,
100 const wxString
& label
,
101 const wxBitmap
& bitmap
= wxNullBitmap
,
103 int indexAccel
= -1);
104 #endif // wxUSE_NOTEBOOK
107 virtual void DrawSliderShaft(wxDC
& dc
,
110 wxOrientation orient
,
113 wxRect
*rectShaft
= NULL
);
115 virtual void DrawSliderThumb(wxDC
& dc
,
117 wxOrientation orient
,
121 virtual void DrawSliderTicks(wxDC
& dc
,
124 wxOrientation orient
,
130 #endif // wxUSE_SLIDER
133 virtual void DrawMenuBarItem(wxDC
& dc
,
135 const wxString
& label
,
137 int indexAccel
= -1);
139 virtual void DrawMenuItem(wxDC
& dc
,
141 const wxMenuGeometryInfo
& geometryInfo
,
142 const wxString
& label
,
143 const wxString
& accel
,
144 const wxBitmap
& bitmap
= wxNullBitmap
,
146 int indexAccel
= -1);
148 virtual void DrawMenuSeparator(wxDC
& dc
,
150 const wxMenuGeometryInfo
& geomInfo
);
151 #endif // wxUSE_MENUS
154 virtual void GetComboBitmaps(wxBitmap
*bmpNormal
,
156 wxBitmap
*bmpPressed
,
157 wxBitmap
*bmpDisabled
);
158 #endif // wxUSE_COMBOBOX
161 virtual wxRect
GetBorderDimensions(wxBorder border
) const;
164 virtual wxSize
GetScrollbarArrowSize() const { return GetStdBmpSize(); }
165 #endif // wxUSE_SCROLLBAR
167 virtual wxSize
GetCheckBitmapSize() const { return GetStdBmpSize(); }
168 virtual wxSize
GetRadioBitmapSize() const { return GetStdBmpSize(); }
171 virtual wxSize
GetToolBarButtonSize(wxCoord
*separator
) const;
173 virtual wxSize
GetToolBarMargin() const;
174 #endif // wxUSE_TOOLBAR
177 virtual wxSize
GetTabIndent() const;
179 virtual wxSize
GetTabPadding() const;
180 #endif // wxUSE_NOTEBOOK
183 virtual wxCoord
GetSliderDim() const;
185 virtual wxCoord
GetSliderTickLen() const;
187 virtual wxRect
GetSliderShaftRect(const wxRect
& rect
,
189 wxOrientation orient
,
190 long style
= 0) const;
192 virtual wxSize
GetSliderThumbSize(const wxRect
& rect
,
194 wxOrientation orient
) const;
195 #endif // wxUSE_SLIDER
197 virtual wxSize
GetProgressBarStep() const;
200 virtual wxSize
GetMenuBarItemSize(const wxSize
& sizeText
) const;
202 virtual wxMenuGeometryInfo
*GetMenuGeometry(wxWindow
*win
,
203 const wxMenu
& menu
) const;
204 #endif // wxUSE_MENUS
207 // override base class border drawing routines: we always draw just a
208 // single simple border
209 void DrawSimpleBorder(wxDC
& dc
, wxRect
*rect
)
210 { DrawRect(dc
, rect
, m_penFg
); }
212 virtual void DrawRaisedBorder(wxDC
& dc
, wxRect
*rect
)
213 { DrawSimpleBorder(dc
, rect
); }
214 virtual void DrawSunkenBorder(wxDC
& dc
, wxRect
*rect
)
215 { DrawSimpleBorder(dc
, rect
); }
216 virtual void DrawAntiSunkenBorder(wxDC
& dc
, wxRect
*rect
)
217 { DrawSimpleBorder(dc
, rect
); }
218 virtual void DrawBoxBorder(wxDC
& dc
, wxRect
*rect
)
219 { DrawSimpleBorder(dc
, rect
); }
220 virtual void DrawStaticBorder(wxDC
& dc
, wxRect
*rect
)
221 { DrawSimpleBorder(dc
, rect
); }
222 virtual void DrawExtraBorder(wxDC
& WXUNUSED(dc
), wxRect
* WXUNUSED(rect
))
223 { /* no extra borders for us */ }
225 // all our XPMs are of this size
226 static wxSize
GetStdBmpSize() { return wxSize(8, 8); }
228 wxBitmap
GetIndicator(IndicatorType indType
, int flags
);
229 virtual wxBitmap
GetCheckBitmap(int flags
)
230 { return GetIndicator(IndicatorType_Check
, flags
); }
231 virtual wxBitmap
GetRadioBitmap(int flags
)
232 { return GetIndicator(IndicatorType_Radio
, flags
); }
234 virtual wxBitmap
GetFrameButtonBitmap(FrameButtonType type
);
237 // the bitmaps returned by GetIndicator()
238 wxBitmap m_bmpIndicators
[IndicatorType_MaxCtrl
]
239 [IndicatorState_MaxCtrl
]
240 [IndicatorStatus_Max
];
242 static const char **ms_xpmIndicators
[IndicatorType_MaxCtrl
]
243 [IndicatorState_MaxCtrl
]
244 [IndicatorStatus_Max
];
246 // the arrow bitmaps used by DrawArrow()
247 wxBitmap m_bmpArrows
[Arrow_Max
];
249 static const char **ms_xpmArrows
[Arrow_Max
];
251 // the close bitmap for the frame for GetFrameButtonBitmap()
252 wxBitmap m_bmpFrameClose
;
254 // pen used for foreground drawing
258 // ----------------------------------------------------------------------------
260 // ----------------------------------------------------------------------------
262 static const char *xpmUnchecked
[] = {
263 /* columns rows colors chars-per-pixel */
278 static const char *xpmChecked
[] = {
279 /* columns rows colors chars-per-pixel */
294 static const char *xpmUndeterminate
[] = {
295 /* columns rows colors chars-per-pixel */
310 static const char *xpmRadioUnchecked
[] = {
311 /* columns rows colors chars-per-pixel */
326 static const char *xpmRadioChecked
[] = {
327 /* columns rows colors chars-per-pixel */
342 const char **wxMonoRenderer::ms_xpmIndicators
[IndicatorType_MaxCtrl
]
343 [IndicatorState_MaxCtrl
]
344 [IndicatorStatus_Max
] =
349 { xpmChecked
, xpmUnchecked
, xpmUndeterminate
},
352 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
355 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
361 { xpmRadioChecked
, xpmRadioUnchecked
, xpmUndeterminate
},
364 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
367 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
371 static const char *xpmLeftArrow
[] = {
372 /* columns rows colors chars-per-pixel */
387 static const char *xpmRightArrow
[] = {
388 /* columns rows colors chars-per-pixel */
403 static const char *xpmUpArrow
[] = {
404 /* columns rows colors chars-per-pixel */
419 static const char *xpmDownArrow
[] = {
420 /* columns rows colors chars-per-pixel */
435 const char **wxMonoRenderer::ms_xpmArrows
[Arrow_Max
] =
437 xpmLeftArrow
, xpmRightArrow
, xpmUpArrow
, xpmDownArrow
,
440 // ----------------------------------------------------------------------------
441 // wxMonoColourScheme: uses just white and black
442 // ----------------------------------------------------------------------------
444 class wxMonoColourScheme
: public wxColourScheme
447 // we use only 2 colours, white and black, but we avoid referring to them
448 // like this, instead use the functions below
449 wxColour
GetFg() const { return wxMONO_FG_COL
; }
450 wxColour
GetBg() const { return wxMONO_BG_COL
; }
452 // implement base class pure virtuals
453 virtual wxColour
Get(StdColour col
) const;
454 virtual wxColour
GetBackground(wxWindow
*win
) const;
457 // ----------------------------------------------------------------------------
459 // ----------------------------------------------------------------------------
461 class wxMonoArtProvider
: public wxArtProvider
464 virtual wxBitmap
CreateBitmap(const wxArtID
& id
,
465 const wxArtClient
& client
,
469 // ----------------------------------------------------------------------------
471 // ----------------------------------------------------------------------------
473 class wxMonoTheme
: public wxTheme
477 virtual ~wxMonoTheme();
479 virtual wxRenderer
*GetRenderer();
480 virtual wxArtProvider
*GetArtProvider();
481 virtual wxInputHandler
*GetInputHandler(const wxString
& control
,
482 wxInputConsumer
*consumer
);
483 virtual wxColourScheme
*GetColourScheme();
486 wxMonoRenderer
*m_renderer
;
487 wxMonoArtProvider
*m_artProvider
;
488 wxMonoColourScheme
*m_scheme
;
490 WX_DECLARE_THEME(mono
)
493 // ============================================================================
495 // ============================================================================
497 WX_IMPLEMENT_THEME(wxMonoTheme
, mono
, wxTRANSLATE("Simple monochrome theme"));
499 // ----------------------------------------------------------------------------
501 // ----------------------------------------------------------------------------
503 wxMonoTheme::wxMonoTheme()
507 m_artProvider
= NULL
;
510 wxMonoTheme::~wxMonoTheme()
514 delete m_artProvider
;
517 wxRenderer
*wxMonoTheme::GetRenderer()
521 m_renderer
= new wxMonoRenderer(GetColourScheme());
527 wxArtProvider
*wxMonoTheme::GetArtProvider()
529 if ( !m_artProvider
)
531 m_artProvider
= new wxMonoArtProvider
;
534 return m_artProvider
;
537 wxColourScheme
*wxMonoTheme::GetColourScheme()
541 m_scheme
= new wxMonoColourScheme
;
547 wxInputHandler
*wxMonoTheme::GetInputHandler(const wxString
& WXUNUSED(control
),
548 wxInputConsumer
*consumer
)
550 // no special input handlers so far
551 return consumer
->DoGetStdInputHandler(NULL
);
554 // ============================================================================
555 // wxMonoColourScheme
556 // ============================================================================
558 wxColour
wxMonoColourScheme::GetBackground(wxWindow
*win
) const
561 if ( win
->UseBgCol() )
563 // use the user specified colour
564 col
= win
->GetBackgroundColour();
567 // doesn't depend on the state
576 wxColour
wxMonoColourScheme::Get(wxMonoColourScheme::StdColour col
) const
582 case CONTROL_PRESSED
:
583 case CONTROL_CURRENT
:
585 case SCROLLBAR_PRESSED
:
588 case TITLEBAR_ACTIVE
:
595 wxFAIL_MSG(_T("invalid standard colour"));
599 case SHADOW_HIGHLIGHT
:
603 case CONTROL_TEXT_DISABLED
:
604 case CONTROL_TEXT_DISABLED_SHADOW
:
606 case TITLEBAR_ACTIVE_TEXT
:
613 // ============================================================================
615 // ============================================================================
617 // ----------------------------------------------------------------------------
619 // ----------------------------------------------------------------------------
621 wxMonoRenderer::wxMonoRenderer(const wxColourScheme
*scheme
)
622 : wxStdRenderer(scheme
)
624 m_penFg
= wxPen(wxMONO_FG_COL
);
627 // ----------------------------------------------------------------------------
629 // ----------------------------------------------------------------------------
631 wxRect
wxMonoRenderer::GetBorderDimensions(wxBorder border
) const
636 case wxBORDER_SIMPLE
:
637 case wxBORDER_STATIC
:
638 case wxBORDER_RAISED
:
639 case wxBORDER_SUNKEN
:
643 case wxBORDER_DOUBLE
:
648 wxFAIL_MSG(_T("unknown border type"));
651 case wxBORDER_DEFAULT
:
666 void wxMonoRenderer::DrawButtonBorder(wxDC
& dc
,
671 DrawBorder(dc
, wxBORDER_SIMPLE
, rect
, flags
, rectIn
);
674 // ----------------------------------------------------------------------------
676 // ----------------------------------------------------------------------------
679 wxMonoRenderer::DrawHorizontalLine(wxDC
& dc
, wxCoord y
, wxCoord x1
, wxCoord x2
)
682 dc
.DrawLine(x1
, y
, x2
+ 1, y
);
686 wxMonoRenderer::DrawVerticalLine(wxDC
& dc
, wxCoord x
, wxCoord y1
, wxCoord y2
)
689 dc
.DrawLine(x
, y1
, x
, y2
+ 1);
692 // ----------------------------------------------------------------------------
694 // ----------------------------------------------------------------------------
696 void wxMonoRenderer::DrawButtonLabel(wxDC
& dc
,
697 const wxString
& label
,
698 const wxBitmap
& image
,
705 dc
.SetTextForeground(m_penFg
.GetColour());
706 dc
.DrawLabel(label
, image
, rect
, alignment
, indexAccel
, rectBounds
);
708 if ( flags
& wxCONTROL_DISABLED
)
710 // this is ugly but I don't know how to show disabled button visually
711 // in monochrome theme otherwise, so cross it out
713 dc
.DrawLine(rect
.GetTopLeft(), rect
.GetBottomRight());
714 dc
.DrawLine(rect
.GetTopRight(), rect
.GetBottomLeft());
718 // ----------------------------------------------------------------------------
720 // ----------------------------------------------------------------------------
722 wxBitmap
wxMonoRenderer::GetIndicator(IndicatorType indType
, int flags
)
724 IndicatorState indState
;
725 IndicatorStatus indStatus
;
726 GetIndicatorsFromFlags(flags
, indState
, indStatus
);
728 wxBitmap
& bmp
= m_bmpIndicators
[indType
][indState
][indStatus
];
731 const char **xpm
= ms_xpmIndicators
[indType
][indState
][indStatus
];
734 // create and cache it
742 wxBitmap
wxMonoRenderer::GetFrameButtonBitmap(FrameButtonType type
)
744 if ( type
== FrameButton_Close
)
746 if ( !m_bmpFrameClose
.Ok() )
748 static const char *xpmFrameClose
[] = {
749 /* columns rows colors chars-per-pixel */
764 m_bmpFrameClose
= wxBitmap(xpmFrameClose
);
767 return m_bmpFrameClose
;
770 // we don't show any other buttons than close
774 // ----------------------------------------------------------------------------
776 // ----------------------------------------------------------------------------
780 void wxMonoRenderer::DrawToolBarButton(wxDC
& dc
,
781 const wxString
& label
,
782 const wxBitmap
& bitmap
,
788 wxFAIL_MSG(_T("TODO"));
791 wxSize
wxMonoRenderer::GetToolBarButtonSize(wxCoord
*separator
) const
793 wxFAIL_MSG(_T("TODO"));
798 wxSize
wxMonoRenderer::GetToolBarMargin() const
800 wxFAIL_MSG(_T("TODO"));
805 #endif // wxUSE_TOOLBAR
807 // ----------------------------------------------------------------------------
809 // ----------------------------------------------------------------------------
813 void wxMonoRenderer::DrawTab(wxDC
& dc
,
816 const wxString
& label
,
817 const wxBitmap
& bitmap
,
821 wxFAIL_MSG(_T("TODO"));
824 wxSize
wxMonoRenderer::GetTabIndent() const
826 wxFAIL_MSG(_T("TODO"));
831 wxSize
wxMonoRenderer::GetTabPadding() const
833 wxFAIL_MSG(_T("TODO"));
838 #endif // wxUSE_NOTEBOOK
840 // ----------------------------------------------------------------------------
842 // ----------------------------------------------------------------------------
846 void wxMonoRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
848 wxBitmap
*bmpPressed
,
849 wxBitmap
*bmpDisabled
)
851 wxFAIL_MSG(_T("TODO"));
854 #endif // wxUSE_COMBOBOX
856 // ----------------------------------------------------------------------------
858 // ----------------------------------------------------------------------------
862 void wxMonoRenderer::DrawMenuBarItem(wxDC
& dc
,
864 const wxString
& label
,
868 wxFAIL_MSG(_T("TODO"));
871 void wxMonoRenderer::DrawMenuItem(wxDC
& dc
,
873 const wxMenuGeometryInfo
& geometryInfo
,
874 const wxString
& label
,
875 const wxString
& accel
,
876 const wxBitmap
& bitmap
,
880 wxFAIL_MSG(_T("TODO"));
883 void wxMonoRenderer::DrawMenuSeparator(wxDC
& dc
,
885 const wxMenuGeometryInfo
& geomInfo
)
887 wxFAIL_MSG(_T("TODO"));
890 wxSize
wxMonoRenderer::GetMenuBarItemSize(const wxSize
& sizeText
) const
892 wxFAIL_MSG(_T("TODO"));
897 wxMenuGeometryInfo
*wxMonoRenderer::GetMenuGeometry(wxWindow
*win
,
898 const wxMenu
& menu
) const
900 wxFAIL_MSG(_T("TODO"));
905 #endif // wxUSE_MENUS
907 // ----------------------------------------------------------------------------
909 // ----------------------------------------------------------------------------
913 void wxMonoRenderer::DrawSliderShaft(wxDC
& dc
,
916 wxOrientation orient
,
921 wxFAIL_MSG(_T("TODO"));
925 void wxMonoRenderer::DrawSliderThumb(wxDC
& dc
,
927 wxOrientation orient
,
931 wxFAIL_MSG(_T("TODO"));
934 void wxMonoRenderer::DrawSliderTicks(wxDC
& dc
,
937 wxOrientation orient
,
944 wxFAIL_MSG(_T("TODO"));
947 wxCoord
wxMonoRenderer::GetSliderDim() const
949 wxFAIL_MSG(_T("TODO"));
954 wxCoord
wxMonoRenderer::GetSliderTickLen() const
956 wxFAIL_MSG(_T("TODO"));
962 wxRect
wxMonoRenderer::GetSliderShaftRect(const wxRect
& rect
,
964 wxOrientation orient
,
967 wxFAIL_MSG(_T("TODO"));
972 wxSize
wxMonoRenderer::GetSliderThumbSize(const wxRect
& rect
,
974 wxOrientation orient
) const
976 wxFAIL_MSG(_T("TODO"));
981 #endif // wxUSE_SLIDER
983 wxSize
wxMonoRenderer::GetProgressBarStep() const
985 wxFAIL_MSG(_T("TODO"));
991 // ----------------------------------------------------------------------------
993 // ----------------------------------------------------------------------------
995 void wxMonoRenderer::DrawArrow(wxDC
& dc
,
1000 ArrowDirection arrowDir
= GetArrowDirection(dir
);
1001 wxCHECK_RET( arrowDir
!= Arrow_Max
, _T("invalid arrow direction") );
1003 wxBitmap
& bmp
= m_bmpArrows
[arrowDir
];
1006 bmp
= wxBitmap(ms_xpmArrows
[arrowDir
]);
1009 wxRect
rectArrow(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
1010 dc
.DrawBitmap(bmp
, rectArrow
.CentreIn(rect
).GetPosition(), true /* use mask */);
1013 void wxMonoRenderer::DrawScrollbarThumb(wxDC
& dc
,
1014 wxOrientation
WXUNUSED(orient
),
1016 int WXUNUSED(flags
))
1018 DrawSolidRect(dc
, wxMONO_FG_COL
, rect
);
1021 void wxMonoRenderer::DrawScrollbarShaft(wxDC
& dc
,
1022 wxOrientation
WXUNUSED(orient
),
1024 int WXUNUSED(flags
))
1026 DrawSolidRect(dc
, wxMONO_BG_COL
, rect
);
1029 // ----------------------------------------------------------------------------
1030 // top level windows
1031 // ----------------------------------------------------------------------------
1034 // ----------------------------------------------------------------------------
1035 // wxMonoArtProvider
1036 // ----------------------------------------------------------------------------
1038 wxBitmap
wxMonoArtProvider::CreateBitmap(const wxArtID
& WXUNUSED(id
),
1039 const wxArtClient
& WXUNUSED(client
),
1040 const wxSize
& WXUNUSED(size
))
1042 return wxNullBitmap
;