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"
27 #if wxUSE_ALL_THEMES || wxUSE_THEME_MONO
33 #include "wx/artprov.h"
34 #include "wx/univ/stdrend.h"
35 #include "wx/univ/inphand.h"
36 #include "wx/univ/colschem.h"
37 #include "wx/univ/theme.h"
39 class wxMonoColourScheme
;
41 #define wxMONO_BG_COL (*wxWHITE)
42 #define wxMONO_FG_COL (*wxBLACK)
44 // ----------------------------------------------------------------------------
45 // wxMonoRenderer: draw the GUI elements in simplest possible way
46 // ----------------------------------------------------------------------------
48 // Warning: many of the methods here are not implemented, the code won't work
49 // if any but a few wxUSE_XXXs are on
50 class wxMonoRenderer
: public wxStdRenderer
53 wxMonoRenderer(const wxColourScheme
*scheme
);
55 virtual void DrawButtonLabel(wxDC
& dc
,
56 const wxString
& label
,
57 const wxBitmap
& image
,
60 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
62 wxRect
*rectBounds
= NULL
);
64 virtual void DrawButtonBorder(wxDC
& dc
,
67 wxRect
*rectIn
= NULL
);
69 virtual void DrawHorizontalLine(wxDC
& dc
,
70 wxCoord y
, wxCoord x1
, wxCoord x2
);
72 virtual void DrawVerticalLine(wxDC
& dc
,
73 wxCoord x
, wxCoord y1
, wxCoord y2
);
75 virtual void DrawArrow(wxDC
& dc
,
79 virtual void DrawScrollbarThumb(wxDC
& dc
,
83 virtual void DrawScrollbarShaft(wxDC
& dc
,
89 virtual void DrawToolBarButton(wxDC
& dc
,
90 const wxString
& label
,
91 const wxBitmap
& bitmap
,
96 #endif // wxUSE_TOOLBAR
99 virtual void DrawTab(wxDC
& dc
,
102 const wxString
& label
,
103 const wxBitmap
& bitmap
= wxNullBitmap
,
105 int indexAccel
= -1);
106 #endif // wxUSE_NOTEBOOK
109 virtual void DrawSliderShaft(wxDC
& dc
,
112 wxOrientation orient
,
115 wxRect
*rectShaft
= NULL
);
117 virtual void DrawSliderThumb(wxDC
& dc
,
119 wxOrientation orient
,
123 virtual void DrawSliderTicks(wxDC
& dc
,
126 wxOrientation orient
,
132 #endif // wxUSE_SLIDER
135 virtual void DrawMenuBarItem(wxDC
& dc
,
137 const wxString
& label
,
139 int indexAccel
= -1);
141 virtual void DrawMenuItem(wxDC
& dc
,
143 const wxMenuGeometryInfo
& geometryInfo
,
144 const wxString
& label
,
145 const wxString
& accel
,
146 const wxBitmap
& bitmap
= wxNullBitmap
,
148 int indexAccel
= -1);
150 virtual void DrawMenuSeparator(wxDC
& dc
,
152 const wxMenuGeometryInfo
& geomInfo
);
153 #endif // wxUSE_MENUS
156 virtual void GetComboBitmaps(wxBitmap
*bmpNormal
,
158 wxBitmap
*bmpPressed
,
159 wxBitmap
*bmpDisabled
);
160 #endif // wxUSE_COMBOBOX
163 virtual wxRect
GetBorderDimensions(wxBorder border
) const;
166 virtual wxSize
GetScrollbarArrowSize() const { return GetStdBmpSize(); }
167 #endif // wxUSE_SCROLLBAR
169 virtual wxSize
GetCheckBitmapSize() const { return GetStdBmpSize(); }
170 virtual wxSize
GetRadioBitmapSize() const { return GetStdBmpSize(); }
173 virtual wxSize
GetToolBarButtonSize(wxCoord
*separator
) const;
175 virtual wxSize
GetToolBarMargin() const;
176 #endif // wxUSE_TOOLBAR
179 virtual wxSize
GetTabIndent() const;
181 virtual wxSize
GetTabPadding() const;
182 #endif // wxUSE_NOTEBOOK
185 virtual wxCoord
GetSliderDim() const;
187 virtual wxCoord
GetSliderTickLen() const;
189 virtual wxRect
GetSliderShaftRect(const wxRect
& rect
,
191 wxOrientation orient
,
192 long style
= 0) const;
194 virtual wxSize
GetSliderThumbSize(const wxRect
& rect
,
196 wxOrientation orient
) const;
197 #endif // wxUSE_SLIDER
199 virtual wxSize
GetProgressBarStep() const;
202 virtual wxSize
GetMenuBarItemSize(const wxSize
& sizeText
) const;
204 virtual wxMenuGeometryInfo
*GetMenuGeometry(wxWindow
*win
,
205 const wxMenu
& menu
) const;
206 #endif // wxUSE_MENUS
209 virtual wxCoord
GetStatusBarBorderBetweenFields() const;
211 virtual wxSize
GetStatusBarFieldMargins() const;
212 #endif // wxUSE_STATUSBAR
215 // override base class border drawing routines: we always draw just a
216 // single simple border
217 void DrawSimpleBorder(wxDC
& dc
, wxRect
*rect
)
218 { DrawRect(dc
, rect
, m_penFg
); }
220 virtual void DrawRaisedBorder(wxDC
& dc
, wxRect
*rect
)
221 { DrawSimpleBorder(dc
, rect
); }
222 virtual void DrawSunkenBorder(wxDC
& dc
, wxRect
*rect
)
223 { DrawSimpleBorder(dc
, rect
); }
224 virtual void DrawAntiSunkenBorder(wxDC
& dc
, wxRect
*rect
)
225 { DrawSimpleBorder(dc
, rect
); }
226 virtual void DrawBoxBorder(wxDC
& dc
, wxRect
*rect
)
227 { DrawSimpleBorder(dc
, rect
); }
228 virtual void DrawStaticBorder(wxDC
& dc
, wxRect
*rect
)
229 { DrawSimpleBorder(dc
, rect
); }
230 virtual void DrawExtraBorder(wxDC
& WXUNUSED(dc
), wxRect
* WXUNUSED(rect
))
231 { /* no extra borders for us */ }
233 // all our XPMs are of this size
234 static wxSize
GetStdBmpSize() { return wxSize(8, 8); }
236 wxBitmap
GetIndicator(IndicatorType indType
, int flags
);
237 virtual wxBitmap
GetCheckBitmap(int flags
)
238 { return GetIndicator(IndicatorType_Check
, flags
); }
239 virtual wxBitmap
GetRadioBitmap(int flags
)
240 { return GetIndicator(IndicatorType_Radio
, flags
); }
242 virtual wxBitmap
GetFrameButtonBitmap(FrameButtonType type
);
243 virtual int GetFrameBorderWidth(int flags
) const;
246 // the bitmaps returned by GetIndicator()
247 wxBitmap m_bmpIndicators
[IndicatorType_MaxCtrl
]
248 [IndicatorState_MaxCtrl
]
249 [IndicatorStatus_Max
];
251 static const char **ms_xpmIndicators
[IndicatorType_MaxCtrl
]
252 [IndicatorState_MaxCtrl
]
253 [IndicatorStatus_Max
];
255 // the arrow bitmaps used by DrawArrow()
256 wxBitmap m_bmpArrows
[Arrow_Max
];
258 static const char **ms_xpmArrows
[Arrow_Max
];
260 // the close bitmap for the frame for GetFrameButtonBitmap()
261 wxBitmap m_bmpFrameClose
;
263 // pen used for foreground drawing
267 // ----------------------------------------------------------------------------
269 // ----------------------------------------------------------------------------
271 static const char *xpmUnchecked
[] = {
272 /* columns rows colors chars-per-pixel */
287 static const char *xpmChecked
[] = {
288 /* columns rows colors chars-per-pixel */
303 static const char *xpmUndeterminate
[] = {
304 /* columns rows colors chars-per-pixel */
319 static const char *xpmRadioUnchecked
[] = {
320 /* columns rows colors chars-per-pixel */
335 static const char *xpmRadioChecked
[] = {
336 /* columns rows colors chars-per-pixel */
351 const char **wxMonoRenderer::ms_xpmIndicators
[IndicatorType_MaxCtrl
]
352 [IndicatorState_MaxCtrl
]
353 [IndicatorStatus_Max
] =
358 { xpmChecked
, xpmUnchecked
, xpmUndeterminate
},
361 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
364 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
370 { xpmRadioChecked
, xpmRadioUnchecked
, xpmUndeterminate
},
373 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
376 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
380 static const char *xpmLeftArrow
[] = {
381 /* columns rows colors chars-per-pixel */
396 static const char *xpmRightArrow
[] = {
397 /* columns rows colors chars-per-pixel */
412 static const char *xpmUpArrow
[] = {
413 /* columns rows colors chars-per-pixel */
428 static const char *xpmDownArrow
[] = {
429 /* columns rows colors chars-per-pixel */
444 const char **wxMonoRenderer::ms_xpmArrows
[Arrow_Max
] =
446 xpmLeftArrow
, xpmRightArrow
, xpmUpArrow
, xpmDownArrow
,
449 // ----------------------------------------------------------------------------
450 // wxMonoColourScheme: uses just white and black
451 // ----------------------------------------------------------------------------
453 class wxMonoColourScheme
: public wxColourScheme
456 // we use only 2 colours, white and black, but we avoid referring to them
457 // like this, instead use the functions below
458 wxColour
GetFg() const { return wxMONO_FG_COL
; }
459 wxColour
GetBg() const { return wxMONO_BG_COL
; }
461 // implement base class pure virtuals
462 virtual wxColour
Get(StdColour col
) const;
463 virtual wxColour
GetBackground(wxWindow
*win
) const;
466 // ----------------------------------------------------------------------------
468 // ----------------------------------------------------------------------------
470 class wxMonoArtProvider
: public wxArtProvider
473 virtual wxBitmap
CreateBitmap(const wxArtID
& id
,
474 const wxArtClient
& client
,
478 // ----------------------------------------------------------------------------
480 // ----------------------------------------------------------------------------
482 class wxMonoTheme
: public wxTheme
486 virtual ~wxMonoTheme();
488 virtual wxRenderer
*GetRenderer();
489 virtual wxArtProvider
*GetArtProvider();
490 virtual wxInputHandler
*GetInputHandler(const wxString
& control
,
491 wxInputConsumer
*consumer
);
492 virtual wxColourScheme
*GetColourScheme();
495 wxMonoRenderer
*m_renderer
;
496 wxMonoArtProvider
*m_artProvider
;
497 wxMonoColourScheme
*m_scheme
;
499 WX_DECLARE_THEME(mono
)
502 // ============================================================================
504 // ============================================================================
506 WX_IMPLEMENT_THEME(wxMonoTheme
, mono
, wxTRANSLATE("Simple monochrome theme"));
508 // ----------------------------------------------------------------------------
510 // ----------------------------------------------------------------------------
512 wxMonoTheme::wxMonoTheme()
516 m_artProvider
= NULL
;
519 wxMonoTheme::~wxMonoTheme()
523 delete m_artProvider
;
526 wxRenderer
*wxMonoTheme::GetRenderer()
530 m_renderer
= new wxMonoRenderer(GetColourScheme());
536 wxArtProvider
*wxMonoTheme::GetArtProvider()
538 if ( !m_artProvider
)
540 m_artProvider
= new wxMonoArtProvider
;
543 return m_artProvider
;
546 wxColourScheme
*wxMonoTheme::GetColourScheme()
550 m_scheme
= new wxMonoColourScheme
;
556 wxInputHandler
*wxMonoTheme::GetInputHandler(const wxString
& WXUNUSED(control
),
557 wxInputConsumer
*consumer
)
559 // no special input handlers so far
560 return consumer
->DoGetStdInputHandler(NULL
);
563 // ============================================================================
564 // wxMonoColourScheme
565 // ============================================================================
567 wxColour
wxMonoColourScheme::GetBackground(wxWindow
*win
) const
570 if ( win
->UseBgCol() )
572 // use the user specified colour
573 col
= win
->GetBackgroundColour();
576 // doesn't depend on the state
585 wxColour
wxMonoColourScheme::Get(wxMonoColourScheme::StdColour col
) const
591 case CONTROL_PRESSED
:
592 case CONTROL_CURRENT
:
594 case SCROLLBAR_PRESSED
:
597 case TITLEBAR_ACTIVE
:
604 wxFAIL_MSG(_T("invalid standard colour"));
608 case SHADOW_HIGHLIGHT
:
612 case CONTROL_TEXT_DISABLED
:
613 case CONTROL_TEXT_DISABLED_SHADOW
:
615 case TITLEBAR_ACTIVE_TEXT
:
622 // ============================================================================
624 // ============================================================================
626 // ----------------------------------------------------------------------------
628 // ----------------------------------------------------------------------------
630 wxMonoRenderer::wxMonoRenderer(const wxColourScheme
*scheme
)
631 : wxStdRenderer(scheme
)
633 m_penFg
= wxPen(wxMONO_FG_COL
);
636 // ----------------------------------------------------------------------------
638 // ----------------------------------------------------------------------------
640 wxRect
wxMonoRenderer::GetBorderDimensions(wxBorder border
) const
645 case wxBORDER_SIMPLE
:
646 case wxBORDER_STATIC
:
647 case wxBORDER_RAISED
:
648 case wxBORDER_SUNKEN
:
652 case wxBORDER_DOUBLE
:
657 wxFAIL_MSG(_T("unknown border type"));
660 case wxBORDER_DEFAULT
:
675 void wxMonoRenderer::DrawButtonBorder(wxDC
& dc
,
680 DrawBorder(dc
, wxBORDER_SIMPLE
, rect
, flags
, rectIn
);
683 // ----------------------------------------------------------------------------
685 // ----------------------------------------------------------------------------
688 wxMonoRenderer::DrawHorizontalLine(wxDC
& dc
, wxCoord y
, wxCoord x1
, wxCoord x2
)
691 dc
.DrawLine(x1
, y
, x2
+ 1, y
);
695 wxMonoRenderer::DrawVerticalLine(wxDC
& dc
, wxCoord x
, wxCoord y1
, wxCoord y2
)
698 dc
.DrawLine(x
, y1
, x
, y2
+ 1);
701 // ----------------------------------------------------------------------------
703 // ----------------------------------------------------------------------------
705 void wxMonoRenderer::DrawButtonLabel(wxDC
& dc
,
706 const wxString
& label
,
707 const wxBitmap
& image
,
714 dc
.SetTextForeground(m_penFg
.GetColour());
715 dc
.DrawLabel(label
, image
, rect
, alignment
, indexAccel
, rectBounds
);
717 if ( flags
& wxCONTROL_DISABLED
)
719 // this is ugly but I don't know how to show disabled button visually
720 // in monochrome theme otherwise, so cross it out
722 dc
.DrawLine(rect
.GetTopLeft(), rect
.GetBottomRight());
723 dc
.DrawLine(rect
.GetTopRight(), rect
.GetBottomLeft());
727 // ----------------------------------------------------------------------------
729 // ----------------------------------------------------------------------------
731 wxBitmap
wxMonoRenderer::GetIndicator(IndicatorType indType
, int flags
)
733 IndicatorState indState
;
734 IndicatorStatus indStatus
;
735 GetIndicatorsFromFlags(flags
, indState
, indStatus
);
737 wxBitmap
& bmp
= m_bmpIndicators
[indType
][indState
][indStatus
];
740 const char **xpm
= ms_xpmIndicators
[indType
][indState
][indStatus
];
743 // create and cache it
751 wxBitmap
wxMonoRenderer::GetFrameButtonBitmap(FrameButtonType type
)
753 if ( type
== FrameButton_Close
)
755 if ( !m_bmpFrameClose
.Ok() )
757 static const char *xpmFrameClose
[] = {
758 /* columns rows colors chars-per-pixel */
773 m_bmpFrameClose
= wxBitmap(xpmFrameClose
);
776 return m_bmpFrameClose
;
779 // we don't show any other buttons than close
783 // ----------------------------------------------------------------------------
785 // ----------------------------------------------------------------------------
789 void wxMonoRenderer::DrawToolBarButton(wxDC
& dc
,
790 const wxString
& label
,
791 const wxBitmap
& bitmap
,
797 wxFAIL_MSG(_T("TODO"));
800 wxSize
wxMonoRenderer::GetToolBarButtonSize(wxCoord
*separator
) const
802 wxFAIL_MSG(_T("TODO"));
807 wxSize
wxMonoRenderer::GetToolBarMargin() const
809 wxFAIL_MSG(_T("TODO"));
814 #endif // wxUSE_TOOLBAR
816 // ----------------------------------------------------------------------------
818 // ----------------------------------------------------------------------------
822 void wxMonoRenderer::DrawTab(wxDC
& dc
,
825 const wxString
& label
,
826 const wxBitmap
& bitmap
,
830 wxFAIL_MSG(_T("TODO"));
833 wxSize
wxMonoRenderer::GetTabIndent() const
835 wxFAIL_MSG(_T("TODO"));
840 wxSize
wxMonoRenderer::GetTabPadding() const
842 wxFAIL_MSG(_T("TODO"));
847 #endif // wxUSE_NOTEBOOK
849 // ----------------------------------------------------------------------------
851 // ----------------------------------------------------------------------------
855 void wxMonoRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
857 wxBitmap
*bmpPressed
,
858 wxBitmap
*bmpDisabled
)
860 wxFAIL_MSG(_T("TODO"));
863 #endif // wxUSE_COMBOBOX
865 // ----------------------------------------------------------------------------
867 // ----------------------------------------------------------------------------
871 void wxMonoRenderer::DrawMenuBarItem(wxDC
& dc
,
873 const wxString
& label
,
877 wxFAIL_MSG(_T("TODO"));
880 void wxMonoRenderer::DrawMenuItem(wxDC
& dc
,
882 const wxMenuGeometryInfo
& geometryInfo
,
883 const wxString
& label
,
884 const wxString
& accel
,
885 const wxBitmap
& bitmap
,
889 wxFAIL_MSG(_T("TODO"));
892 void wxMonoRenderer::DrawMenuSeparator(wxDC
& dc
,
894 const wxMenuGeometryInfo
& geomInfo
)
896 wxFAIL_MSG(_T("TODO"));
899 wxSize
wxMonoRenderer::GetMenuBarItemSize(const wxSize
& sizeText
) const
901 wxFAIL_MSG(_T("TODO"));
906 wxMenuGeometryInfo
*wxMonoRenderer::GetMenuGeometry(wxWindow
*win
,
907 const wxMenu
& menu
) const
909 wxFAIL_MSG(_T("TODO"));
914 #endif // wxUSE_MENUS
916 // ----------------------------------------------------------------------------
918 // ----------------------------------------------------------------------------
922 void wxMonoRenderer::DrawSliderShaft(wxDC
& dc
,
925 wxOrientation orient
,
930 wxFAIL_MSG(_T("TODO"));
934 void wxMonoRenderer::DrawSliderThumb(wxDC
& dc
,
936 wxOrientation orient
,
940 wxFAIL_MSG(_T("TODO"));
943 void wxMonoRenderer::DrawSliderTicks(wxDC
& dc
,
946 wxOrientation orient
,
953 wxFAIL_MSG(_T("TODO"));
956 wxCoord
wxMonoRenderer::GetSliderDim() const
958 wxFAIL_MSG(_T("TODO"));
963 wxCoord
wxMonoRenderer::GetSliderTickLen() const
965 wxFAIL_MSG(_T("TODO"));
971 wxRect
wxMonoRenderer::GetSliderShaftRect(const wxRect
& rect
,
973 wxOrientation orient
,
976 wxFAIL_MSG(_T("TODO"));
981 wxSize
wxMonoRenderer::GetSliderThumbSize(const wxRect
& rect
,
983 wxOrientation orient
) const
985 wxFAIL_MSG(_T("TODO"));
990 #endif // wxUSE_SLIDER
992 wxSize
wxMonoRenderer::GetProgressBarStep() const
994 wxFAIL_MSG(_T("TODO"));
1000 // ----------------------------------------------------------------------------
1002 // ----------------------------------------------------------------------------
1004 void wxMonoRenderer::DrawArrow(wxDC
& dc
,
1007 int WXUNUSED(flags
))
1009 ArrowDirection arrowDir
= GetArrowDirection(dir
);
1010 wxCHECK_RET( arrowDir
!= Arrow_Max
, _T("invalid arrow direction") );
1012 wxBitmap
& bmp
= m_bmpArrows
[arrowDir
];
1015 bmp
= wxBitmap(ms_xpmArrows
[arrowDir
]);
1018 wxRect
rectArrow(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
1019 dc
.DrawBitmap(bmp
, rectArrow
.CentreIn(rect
).GetPosition(), true /* use mask */);
1022 void wxMonoRenderer::DrawScrollbarThumb(wxDC
& dc
,
1023 wxOrientation
WXUNUSED(orient
),
1025 int WXUNUSED(flags
))
1027 DrawSolidRect(dc
, wxMONO_FG_COL
, rect
);
1030 void wxMonoRenderer::DrawScrollbarShaft(wxDC
& dc
,
1031 wxOrientation
WXUNUSED(orient
),
1033 int WXUNUSED(flags
))
1035 DrawSolidRect(dc
, wxMONO_BG_COL
, rect
);
1038 // ----------------------------------------------------------------------------
1040 // ----------------------------------------------------------------------------
1044 wxCoord
wxMonoRenderer::GetStatusBarBorderBetweenFields() const
1049 wxSize
wxMonoRenderer::GetStatusBarFieldMargins() const
1051 return wxSize(1, 1);
1054 #endif // wxUSE_STATUSBAR
1056 // ----------------------------------------------------------------------------
1057 // top level windows
1058 // ----------------------------------------------------------------------------
1060 int wxMonoRenderer::GetFrameBorderWidth(int WXUNUSED(flags
)) const
1062 // all our borders are simple
1066 // ----------------------------------------------------------------------------
1067 // wxMonoArtProvider
1068 // ----------------------------------------------------------------------------
1070 wxBitmap
wxMonoArtProvider::CreateBitmap(const wxArtID
& WXUNUSED(id
),
1071 const wxArtClient
& WXUNUSED(client
),
1072 const wxSize
& WXUNUSED(size
))
1074 return wxNullBitmap
;
1077 #endif // wxUSE_ALL_THEMES || wxUSE_THEME_MONO