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 #include "wx/univ/theme.h"
35 #include "wx/artprov.h"
36 #include "wx/univ/stdrend.h"
37 #include "wx/univ/inphand.h"
38 #include "wx/univ/colschem.h"
40 class wxMonoColourScheme
;
42 #define wxMONO_BG_COL (*wxWHITE)
43 #define wxMONO_FG_COL (*wxBLACK)
45 // ----------------------------------------------------------------------------
46 // wxMonoRenderer: draw the GUI elements in simplest possible way
47 // ----------------------------------------------------------------------------
49 // Warning: many of the methods here are not implemented, the code won't work
50 // if any but a few wxUSE_XXXs are on
51 class wxMonoRenderer
: public wxStdRenderer
54 wxMonoRenderer(const wxColourScheme
*scheme
);
56 virtual void DrawButtonLabel(wxDC
& dc
,
57 const wxString
& label
,
58 const wxBitmap
& image
,
61 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
63 wxRect
*rectBounds
= NULL
);
65 virtual void DrawFocusRect(wxDC
& dc
, const wxRect
& rect
, int flags
= 0);
67 virtual void DrawButtonBorder(wxDC
& dc
,
70 wxRect
*rectIn
= NULL
);
72 virtual void DrawHorizontalLine(wxDC
& dc
,
73 wxCoord y
, wxCoord x1
, wxCoord x2
);
75 virtual void DrawVerticalLine(wxDC
& dc
,
76 wxCoord x
, wxCoord y1
, wxCoord y2
);
78 virtual void DrawArrow(wxDC
& dc
,
82 virtual void DrawScrollbarThumb(wxDC
& dc
,
86 virtual void DrawScrollbarShaft(wxDC
& dc
,
92 virtual void DrawToolBarButton(wxDC
& dc
,
93 const wxString
& label
,
94 const wxBitmap
& bitmap
,
99 #endif // wxUSE_TOOLBAR
102 virtual void DrawTab(wxDC
& dc
,
105 const wxString
& label
,
106 const wxBitmap
& bitmap
= wxNullBitmap
,
108 int indexAccel
= -1);
109 #endif // wxUSE_NOTEBOOK
112 virtual void DrawSliderShaft(wxDC
& dc
,
115 wxOrientation orient
,
118 wxRect
*rectShaft
= NULL
);
120 virtual void DrawSliderThumb(wxDC
& dc
,
122 wxOrientation orient
,
126 virtual void DrawSliderTicks(wxDC
& dc
,
129 wxOrientation orient
,
135 #endif // wxUSE_SLIDER
138 virtual void DrawMenuBarItem(wxDC
& dc
,
140 const wxString
& label
,
142 int indexAccel
= -1);
144 virtual void DrawMenuItem(wxDC
& dc
,
146 const wxMenuGeometryInfo
& geometryInfo
,
147 const wxString
& label
,
148 const wxString
& accel
,
149 const wxBitmap
& bitmap
= wxNullBitmap
,
151 int indexAccel
= -1);
153 virtual void DrawMenuSeparator(wxDC
& dc
,
155 const wxMenuGeometryInfo
& geomInfo
);
156 #endif // wxUSE_MENUS
159 virtual void GetComboBitmaps(wxBitmap
*bmpNormal
,
161 wxBitmap
*bmpPressed
,
162 wxBitmap
*bmpDisabled
);
163 #endif // wxUSE_COMBOBOX
166 virtual wxRect
GetBorderDimensions(wxBorder border
) const;
169 virtual wxSize
GetScrollbarArrowSize() const { return GetStdBmpSize(); }
170 #endif // wxUSE_SCROLLBAR
172 virtual wxSize
GetCheckBitmapSize() const { return GetStdBmpSize(); }
173 virtual wxSize
GetRadioBitmapSize() const { return GetStdBmpSize(); }
176 virtual wxSize
GetToolBarButtonSize(wxCoord
*separator
) const;
178 virtual wxSize
GetToolBarMargin() const;
179 #endif // wxUSE_TOOLBAR
182 virtual wxSize
GetTabIndent() const;
184 virtual wxSize
GetTabPadding() const;
185 #endif // wxUSE_NOTEBOOK
188 virtual wxCoord
GetSliderDim() const;
190 virtual wxCoord
GetSliderTickLen() const;
192 virtual wxRect
GetSliderShaftRect(const wxRect
& rect
,
194 wxOrientation orient
,
195 long style
= 0) const;
197 virtual wxSize
GetSliderThumbSize(const wxRect
& rect
,
199 wxOrientation orient
) const;
200 #endif // wxUSE_SLIDER
202 virtual wxSize
GetProgressBarStep() const;
205 virtual wxSize
GetMenuBarItemSize(const wxSize
& sizeText
) const;
207 virtual wxMenuGeometryInfo
*GetMenuGeometry(wxWindow
*win
,
208 const wxMenu
& menu
) const;
209 #endif // wxUSE_MENUS
212 virtual wxCoord
GetStatusBarBorderBetweenFields() const;
214 virtual wxSize
GetStatusBarFieldMargins() const;
215 #endif // wxUSE_STATUSBAR
218 // override base class border drawing routines: we always draw just a
219 // single simple border
220 void DrawSimpleBorder(wxDC
& dc
, wxRect
*rect
)
221 { DrawRect(dc
, rect
, m_penFg
); }
223 virtual void DrawRaisedBorder(wxDC
& dc
, wxRect
*rect
)
224 { DrawSimpleBorder(dc
, rect
); }
225 virtual void DrawSunkenBorder(wxDC
& dc
, wxRect
*rect
)
226 { DrawSimpleBorder(dc
, rect
); }
227 virtual void DrawAntiSunkenBorder(wxDC
& dc
, wxRect
*rect
)
228 { DrawSimpleBorder(dc
, rect
); }
229 virtual void DrawBoxBorder(wxDC
& dc
, wxRect
*rect
)
230 { DrawSimpleBorder(dc
, rect
); }
231 virtual void DrawStaticBorder(wxDC
& dc
, wxRect
*rect
)
232 { DrawSimpleBorder(dc
, rect
); }
233 virtual void DrawExtraBorder(wxDC
& WXUNUSED(dc
), wxRect
* WXUNUSED(rect
))
234 { /* no extra borders for us */ }
236 // all our XPMs are of this size
237 static wxSize
GetStdBmpSize() { return wxSize(8, 8); }
239 wxBitmap
GetIndicator(IndicatorType indType
, int flags
);
240 virtual wxBitmap
GetCheckBitmap(int flags
)
241 { return GetIndicator(IndicatorType_Check
, flags
); }
242 virtual wxBitmap
GetRadioBitmap(int flags
)
243 { return GetIndicator(IndicatorType_Radio
, flags
); }
245 virtual wxBitmap
GetFrameButtonBitmap(FrameButtonType type
);
246 virtual int GetFrameBorderWidth(int flags
) const;
249 // the bitmaps returned by GetIndicator()
250 wxBitmap m_bmpIndicators
[IndicatorType_MaxCtrl
]
251 [IndicatorState_MaxCtrl
]
252 [IndicatorStatus_Max
];
254 static const char **ms_xpmIndicators
[IndicatorType_MaxCtrl
]
255 [IndicatorState_MaxCtrl
]
256 [IndicatorStatus_Max
];
258 // the arrow bitmaps used by DrawArrow()
259 wxBitmap m_bmpArrows
[Arrow_Max
];
261 static const char **ms_xpmArrows
[Arrow_Max
];
263 // the close bitmap for the frame for GetFrameButtonBitmap()
264 wxBitmap m_bmpFrameClose
;
266 // pen used for foreground drawing
270 // ----------------------------------------------------------------------------
272 // ----------------------------------------------------------------------------
274 static const char *xpmUnchecked
[] = {
275 /* columns rows colors chars-per-pixel */
290 static const char *xpmChecked
[] = {
291 /* columns rows colors chars-per-pixel */
306 static const char *xpmUndeterminate
[] = {
307 /* columns rows colors chars-per-pixel */
322 static const char *xpmRadioUnchecked
[] = {
323 /* columns rows colors chars-per-pixel */
338 static const char *xpmRadioChecked
[] = {
339 /* columns rows colors chars-per-pixel */
354 const char **wxMonoRenderer::ms_xpmIndicators
[IndicatorType_MaxCtrl
]
355 [IndicatorState_MaxCtrl
]
356 [IndicatorStatus_Max
] =
361 { xpmChecked
, xpmUnchecked
, xpmUndeterminate
},
364 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
367 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
373 { xpmRadioChecked
, xpmRadioUnchecked
, xpmUndeterminate
},
376 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
379 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
383 static const char *xpmLeftArrow
[] = {
384 /* columns rows colors chars-per-pixel */
399 static const char *xpmRightArrow
[] = {
400 /* columns rows colors chars-per-pixel */
415 static const char *xpmUpArrow
[] = {
416 /* columns rows colors chars-per-pixel */
431 static const char *xpmDownArrow
[] = {
432 /* columns rows colors chars-per-pixel */
447 const char **wxMonoRenderer::ms_xpmArrows
[Arrow_Max
] =
449 xpmLeftArrow
, xpmRightArrow
, xpmUpArrow
, xpmDownArrow
,
452 // ----------------------------------------------------------------------------
453 // wxMonoColourScheme: uses just white and black
454 // ----------------------------------------------------------------------------
456 class wxMonoColourScheme
: public wxColourScheme
459 // we use only 2 colours, white and black, but we avoid referring to them
460 // like this, instead use the functions below
461 wxColour
GetFg() const { return wxMONO_FG_COL
; }
462 wxColour
GetBg() const { return wxMONO_BG_COL
; }
464 // implement base class pure virtuals
465 virtual wxColour
Get(StdColour col
) const;
466 virtual wxColour
GetBackground(wxWindow
*win
) const;
469 // ----------------------------------------------------------------------------
471 // ----------------------------------------------------------------------------
473 class wxMonoArtProvider
: public wxArtProvider
476 virtual wxBitmap
CreateBitmap(const wxArtID
& id
,
477 const wxArtClient
& client
,
481 // ----------------------------------------------------------------------------
483 // ----------------------------------------------------------------------------
485 class wxMonoTheme
: public wxTheme
489 virtual ~wxMonoTheme();
491 virtual wxRenderer
*GetRenderer();
492 virtual wxArtProvider
*GetArtProvider();
493 virtual wxInputHandler
*GetInputHandler(const wxString
& control
,
494 wxInputConsumer
*consumer
);
495 virtual wxColourScheme
*GetColourScheme();
498 wxMonoRenderer
*m_renderer
;
499 wxMonoArtProvider
*m_artProvider
;
500 wxMonoColourScheme
*m_scheme
;
502 WX_DECLARE_THEME(mono
)
505 // ============================================================================
507 // ============================================================================
509 WX_IMPLEMENT_THEME(wxMonoTheme
, mono
, wxTRANSLATE("Simple monochrome theme"));
511 // ----------------------------------------------------------------------------
513 // ----------------------------------------------------------------------------
515 wxMonoTheme::wxMonoTheme()
519 m_artProvider
= NULL
;
522 wxMonoTheme::~wxMonoTheme()
526 delete m_artProvider
;
529 wxRenderer
*wxMonoTheme::GetRenderer()
533 m_renderer
= new wxMonoRenderer(GetColourScheme());
539 wxArtProvider
*wxMonoTheme::GetArtProvider()
541 if ( !m_artProvider
)
543 m_artProvider
= new wxMonoArtProvider
;
546 return m_artProvider
;
549 wxColourScheme
*wxMonoTheme::GetColourScheme()
553 m_scheme
= new wxMonoColourScheme
;
559 wxInputHandler
*wxMonoTheme::GetInputHandler(const wxString
& WXUNUSED(control
),
560 wxInputConsumer
*consumer
)
562 // no special input handlers so far
563 return consumer
->DoGetStdInputHandler(NULL
);
566 // ============================================================================
567 // wxMonoColourScheme
568 // ============================================================================
570 wxColour
wxMonoColourScheme::GetBackground(wxWindow
*win
) const
573 if ( win
->UseBgCol() )
575 // use the user specified colour
576 col
= win
->GetBackgroundColour();
579 // doesn't depend on the state
588 wxColour
wxMonoColourScheme::Get(wxMonoColourScheme::StdColour col
) const
594 case CONTROL_PRESSED
:
595 case CONTROL_CURRENT
:
597 case SCROLLBAR_PRESSED
:
600 case TITLEBAR_ACTIVE
:
607 wxFAIL_MSG(_T("invalid standard colour"));
611 case SHADOW_HIGHLIGHT
:
615 case CONTROL_TEXT_DISABLED
:
616 case CONTROL_TEXT_DISABLED_SHADOW
:
618 case TITLEBAR_ACTIVE_TEXT
:
625 // ============================================================================
627 // ============================================================================
629 // ----------------------------------------------------------------------------
631 // ----------------------------------------------------------------------------
633 wxMonoRenderer::wxMonoRenderer(const wxColourScheme
*scheme
)
634 : wxStdRenderer(scheme
)
636 m_penFg
= wxPen(wxMONO_FG_COL
);
639 // ----------------------------------------------------------------------------
641 // ----------------------------------------------------------------------------
643 wxRect
wxMonoRenderer::GetBorderDimensions(wxBorder border
) const
648 case wxBORDER_SIMPLE
:
649 case wxBORDER_STATIC
:
650 case wxBORDER_RAISED
:
651 case wxBORDER_SUNKEN
:
655 case wxBORDER_DOUBLE
:
660 wxFAIL_MSG(_T("unknown border type"));
663 case wxBORDER_DEFAULT
:
678 void wxMonoRenderer::DrawButtonBorder(wxDC
& dc
,
683 DrawBorder(dc
, wxBORDER_SIMPLE
, rect
, flags
, rectIn
);
686 // ----------------------------------------------------------------------------
688 // ----------------------------------------------------------------------------
691 wxMonoRenderer::DrawHorizontalLine(wxDC
& dc
, wxCoord y
, wxCoord x1
, wxCoord x2
)
694 dc
.DrawLine(x1
, y
, x2
+ 1, y
);
698 wxMonoRenderer::DrawVerticalLine(wxDC
& dc
, wxCoord x
, wxCoord y1
, wxCoord y2
)
701 dc
.DrawLine(x
, y1
, x
, y2
+ 1);
704 void wxMonoRenderer::DrawFocusRect(wxDC
& dc
, const wxRect
& rect
, int flags
)
706 // no need to draw the focus rect for selected items, it would be invisible
708 if ( !(flags
& wxCONTROL_SELECTED
) )
711 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
712 dc
.DrawRectangle(rect
);
716 // ----------------------------------------------------------------------------
718 // ----------------------------------------------------------------------------
720 void wxMonoRenderer::DrawButtonLabel(wxDC
& dc
,
721 const wxString
& label
,
722 const wxBitmap
& image
,
729 dc
.SetTextForeground(m_penFg
.GetColour());
730 dc
.DrawLabel(label
, image
, rect
, alignment
, indexAccel
, rectBounds
);
732 if ( flags
& wxCONTROL_DISABLED
)
734 // this is ugly but I don't know how to show disabled button visually
735 // in monochrome theme otherwise, so cross it out
737 dc
.DrawLine(rect
.GetTopLeft(), rect
.GetBottomRight());
738 dc
.DrawLine(rect
.GetTopRight(), rect
.GetBottomLeft());
742 // ----------------------------------------------------------------------------
744 // ----------------------------------------------------------------------------
746 wxBitmap
wxMonoRenderer::GetIndicator(IndicatorType indType
, int flags
)
748 IndicatorState indState
;
749 IndicatorStatus indStatus
;
750 GetIndicatorsFromFlags(flags
, indState
, indStatus
);
752 wxBitmap
& bmp
= m_bmpIndicators
[indType
][indState
][indStatus
];
755 const char **xpm
= ms_xpmIndicators
[indType
][indState
][indStatus
];
758 // create and cache it
766 wxBitmap
wxMonoRenderer::GetFrameButtonBitmap(FrameButtonType type
)
768 if ( type
== FrameButton_Close
)
770 if ( !m_bmpFrameClose
.Ok() )
772 static const char *xpmFrameClose
[] = {
773 /* columns rows colors chars-per-pixel */
788 m_bmpFrameClose
= wxBitmap(xpmFrameClose
);
791 return m_bmpFrameClose
;
794 // we don't show any other buttons than close
798 // ----------------------------------------------------------------------------
800 // ----------------------------------------------------------------------------
804 void wxMonoRenderer::DrawToolBarButton(wxDC
& dc
,
805 const wxString
& label
,
806 const wxBitmap
& bitmap
,
812 wxFAIL_MSG(_T("TODO"));
815 wxSize
wxMonoRenderer::GetToolBarButtonSize(wxCoord
*separator
) const
817 wxFAIL_MSG(_T("TODO"));
822 wxSize
wxMonoRenderer::GetToolBarMargin() const
824 wxFAIL_MSG(_T("TODO"));
829 #endif // wxUSE_TOOLBAR
831 // ----------------------------------------------------------------------------
833 // ----------------------------------------------------------------------------
837 void wxMonoRenderer::DrawTab(wxDC
& dc
,
840 const wxString
& label
,
841 const wxBitmap
& bitmap
,
845 wxFAIL_MSG(_T("TODO"));
848 wxSize
wxMonoRenderer::GetTabIndent() const
850 wxFAIL_MSG(_T("TODO"));
855 wxSize
wxMonoRenderer::GetTabPadding() const
857 wxFAIL_MSG(_T("TODO"));
862 #endif // wxUSE_NOTEBOOK
864 // ----------------------------------------------------------------------------
866 // ----------------------------------------------------------------------------
870 void wxMonoRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
872 wxBitmap
*bmpPressed
,
873 wxBitmap
*bmpDisabled
)
875 wxFAIL_MSG(_T("TODO"));
878 #endif // wxUSE_COMBOBOX
880 // ----------------------------------------------------------------------------
882 // ----------------------------------------------------------------------------
886 void wxMonoRenderer::DrawMenuBarItem(wxDC
& dc
,
888 const wxString
& label
,
892 wxFAIL_MSG(_T("TODO"));
895 void wxMonoRenderer::DrawMenuItem(wxDC
& dc
,
897 const wxMenuGeometryInfo
& geometryInfo
,
898 const wxString
& label
,
899 const wxString
& accel
,
900 const wxBitmap
& bitmap
,
904 wxFAIL_MSG(_T("TODO"));
907 void wxMonoRenderer::DrawMenuSeparator(wxDC
& dc
,
909 const wxMenuGeometryInfo
& geomInfo
)
911 wxFAIL_MSG(_T("TODO"));
914 wxSize
wxMonoRenderer::GetMenuBarItemSize(const wxSize
& sizeText
) const
916 wxFAIL_MSG(_T("TODO"));
921 wxMenuGeometryInfo
*wxMonoRenderer::GetMenuGeometry(wxWindow
*win
,
922 const wxMenu
& menu
) const
924 wxFAIL_MSG(_T("TODO"));
929 #endif // wxUSE_MENUS
931 // ----------------------------------------------------------------------------
933 // ----------------------------------------------------------------------------
937 void wxMonoRenderer::DrawSliderShaft(wxDC
& dc
,
940 wxOrientation orient
,
945 wxFAIL_MSG(_T("TODO"));
949 void wxMonoRenderer::DrawSliderThumb(wxDC
& dc
,
951 wxOrientation orient
,
955 wxFAIL_MSG(_T("TODO"));
958 void wxMonoRenderer::DrawSliderTicks(wxDC
& dc
,
961 wxOrientation orient
,
968 wxFAIL_MSG(_T("TODO"));
971 wxCoord
wxMonoRenderer::GetSliderDim() const
973 wxFAIL_MSG(_T("TODO"));
978 wxCoord
wxMonoRenderer::GetSliderTickLen() const
980 wxFAIL_MSG(_T("TODO"));
986 wxRect
wxMonoRenderer::GetSliderShaftRect(const wxRect
& rect
,
988 wxOrientation orient
,
991 wxFAIL_MSG(_T("TODO"));
996 wxSize
wxMonoRenderer::GetSliderThumbSize(const wxRect
& rect
,
998 wxOrientation orient
) const
1000 wxFAIL_MSG(_T("TODO"));
1005 #endif // wxUSE_SLIDER
1007 wxSize
wxMonoRenderer::GetProgressBarStep() const
1009 wxFAIL_MSG(_T("TODO"));
1015 // ----------------------------------------------------------------------------
1017 // ----------------------------------------------------------------------------
1019 void wxMonoRenderer::DrawArrow(wxDC
& dc
,
1022 int WXUNUSED(flags
))
1024 ArrowDirection arrowDir
= GetArrowDirection(dir
);
1025 wxCHECK_RET( arrowDir
!= Arrow_Max
, _T("invalid arrow direction") );
1027 wxBitmap
& bmp
= m_bmpArrows
[arrowDir
];
1030 bmp
= wxBitmap(ms_xpmArrows
[arrowDir
]);
1033 wxRect
rectArrow(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
1034 dc
.DrawBitmap(bmp
, rectArrow
.CentreIn(rect
).GetPosition(), true /* use mask */);
1037 void wxMonoRenderer::DrawScrollbarThumb(wxDC
& dc
,
1038 wxOrientation
WXUNUSED(orient
),
1040 int WXUNUSED(flags
))
1042 DrawSolidRect(dc
, wxMONO_FG_COL
, rect
);
1045 void wxMonoRenderer::DrawScrollbarShaft(wxDC
& dc
,
1046 wxOrientation
WXUNUSED(orient
),
1048 int WXUNUSED(flags
))
1050 DrawSolidRect(dc
, wxMONO_BG_COL
, rect
);
1053 // ----------------------------------------------------------------------------
1055 // ----------------------------------------------------------------------------
1059 wxCoord
wxMonoRenderer::GetStatusBarBorderBetweenFields() const
1064 wxSize
wxMonoRenderer::GetStatusBarFieldMargins() const
1066 return wxSize(1, 1);
1069 #endif // wxUSE_STATUSBAR
1071 // ----------------------------------------------------------------------------
1072 // top level windows
1073 // ----------------------------------------------------------------------------
1075 int wxMonoRenderer::GetFrameBorderWidth(int WXUNUSED(flags
)) const
1077 // all our borders are simple
1081 // ----------------------------------------------------------------------------
1082 // wxMonoArtProvider
1083 // ----------------------------------------------------------------------------
1085 wxBitmap
wxMonoArtProvider::CreateBitmap(const wxArtID
& WXUNUSED(id
),
1086 const wxArtClient
& WXUNUSED(client
),
1087 const wxSize
& WXUNUSED(size
))
1089 return wxNullBitmap
;
1092 #endif // wxUSE_THEME_MONO