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"
30 #include "wx/artprov.h"
31 #include "wx/univ/stdrend.h"
32 #include "wx/univ/inphand.h"
33 #include "wx/univ/colschem.h"
34 #include "wx/univ/theme.h"
36 class wxMonoColourScheme
;
38 #define wxMONO_BG_COL (*wxWHITE)
39 #define wxMONO_FG_COL (*wxBLACK)
41 // ----------------------------------------------------------------------------
42 // wxMonoRenderer: draw the GUI elements in simplest possible way
43 // ----------------------------------------------------------------------------
45 // Warning: many of the methods here are not implemented, the code won't work
46 // if any but a few wxUSE_XXXs are on
47 class wxMonoRenderer
: public wxStdRenderer
50 wxMonoRenderer(const wxColourScheme
*scheme
);
52 virtual void DrawButtonLabel(wxDC
& dc
,
53 const wxString
& label
,
54 const wxBitmap
& image
,
57 int alignment
= wxALIGN_LEFT
| wxALIGN_TOP
,
59 wxRect
*rectBounds
= NULL
);
61 virtual void DrawBorder(wxDC
& dc
,
65 wxRect
*rectIn
= NULL
);
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 // override base class border drawing routines: we always draw just a
213 // single simple border
214 void DrawSimpleBorder(wxDC
& dc
, wxRect
*rect
)
215 { DrawRect(dc
, rect
, m_penFg
); }
217 virtual void DrawRaisedBorder(wxDC
& dc
, wxRect
*rect
)
218 { DrawSimpleBorder(dc
, rect
); }
219 virtual void DrawSunkenBorder(wxDC
& dc
, wxRect
*rect
)
220 { DrawSimpleBorder(dc
, rect
); }
221 virtual void DrawAntiSunkenBorder(wxDC
& dc
, wxRect
*rect
)
222 { DrawSimpleBorder(dc
, rect
); }
223 virtual void DrawFrameBorder(wxDC
& dc
, wxRect
*rect
)
224 { DrawSimpleBorder(dc
, rect
); }
226 // all our XPMs are of this size
227 static wxSize
GetStdBmpSize() { return wxSize(8, 8); }
229 wxBitmap
GetIndicator(IndicatorType indType
, int flags
);
230 virtual wxBitmap
GetCheckBitmap(int flags
)
231 { return GetIndicator(IndicatorType_Check
, flags
); }
232 virtual wxBitmap
GetRadioBitmap(int flags
)
233 { return GetIndicator(IndicatorType_Radio
, flags
); }
235 virtual wxBitmap
GetFrameButtonBitmap(FrameButtonType type
);
238 // the bitmaps returned by GetIndicator()
239 wxBitmap m_bmpIndicators
[IndicatorType_MaxCtrl
]
240 [IndicatorState_MaxCtrl
]
241 [IndicatorStatus_Max
];
243 static const char **ms_xpmIndicators
[IndicatorType_MaxCtrl
]
244 [IndicatorState_MaxCtrl
]
245 [IndicatorStatus_Max
];
247 // the arrow bitmaps used by DrawArrow()
248 wxBitmap m_bmpArrows
[Arrow_Max
];
250 static const char **ms_xpmArrows
[Arrow_Max
];
252 // the close bitmap for the frame for GetFrameButtonBitmap()
253 wxBitmap m_bmpFrameClose
;
255 // pen used for foreground drawing
259 // ----------------------------------------------------------------------------
261 // ----------------------------------------------------------------------------
263 static const char *xpmUnchecked
[] = {
264 /* columns rows colors chars-per-pixel */
279 static const char *xpmChecked
[] = {
280 /* columns rows colors chars-per-pixel */
295 static const char *xpmUndeterminate
[] = {
296 /* columns rows colors chars-per-pixel */
311 static const char *xpmRadioUnchecked
[] = {
312 /* columns rows colors chars-per-pixel */
327 static const char *xpmRadioChecked
[] = {
328 /* columns rows colors chars-per-pixel */
343 const char **wxMonoRenderer::ms_xpmIndicators
[IndicatorType_MaxCtrl
]
344 [IndicatorState_MaxCtrl
]
345 [IndicatorStatus_Max
] =
350 { xpmChecked
, xpmUnchecked
, xpmUndeterminate
},
353 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
356 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
362 { xpmRadioChecked
, xpmRadioUnchecked
, xpmUndeterminate
},
365 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
368 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
372 static const char *xpmLeftArrow
[] = {
373 /* columns rows colors chars-per-pixel */
388 static const char *xpmRightArrow
[] = {
389 /* columns rows colors chars-per-pixel */
404 static const char *xpmUpArrow
[] = {
405 /* columns rows colors chars-per-pixel */
420 static const char *xpmDownArrow
[] = {
421 /* columns rows colors chars-per-pixel */
436 const char **wxMonoRenderer::ms_xpmArrows
[Arrow_Max
] =
438 xpmLeftArrow
, xpmRightArrow
, xpmUpArrow
, xpmDownArrow
,
441 // ----------------------------------------------------------------------------
442 // wxMonoColourScheme: uses just white and black
443 // ----------------------------------------------------------------------------
445 class wxMonoColourScheme
: public wxColourScheme
448 // we use only 2 colours, white and black, but we avoid referring to them
449 // like this, instead use the functions below
450 wxColour
GetFg() const { return wxMONO_FG_COL
; }
451 wxColour
GetBg() const { return wxMONO_BG_COL
; }
453 // implement base class pure virtuals
454 virtual wxColour
Get(StdColour col
) const;
455 virtual wxColour
GetBackground(wxWindow
*win
) const;
458 // ----------------------------------------------------------------------------
460 // ----------------------------------------------------------------------------
462 class wxMonoArtProvider
: public wxArtProvider
465 virtual wxBitmap
CreateBitmap(const wxArtID
& id
,
466 const wxArtClient
& client
,
470 // ----------------------------------------------------------------------------
472 // ----------------------------------------------------------------------------
474 class wxMonoTheme
: public wxTheme
478 virtual ~wxMonoTheme();
480 virtual wxRenderer
*GetRenderer();
481 virtual wxArtProvider
*GetArtProvider();
482 virtual wxInputHandler
*GetInputHandler(const wxString
& control
,
483 wxInputConsumer
*consumer
);
484 virtual wxColourScheme
*GetColourScheme();
487 wxMonoRenderer
*m_renderer
;
488 wxMonoArtProvider
*m_artProvider
;
489 wxMonoColourScheme
*m_scheme
;
491 WX_DECLARE_THEME(mono
)
494 // ============================================================================
496 // ============================================================================
498 WX_IMPLEMENT_THEME(wxMonoTheme
, mono
, wxTRANSLATE("Simple monochrome theme"));
500 // ----------------------------------------------------------------------------
502 // ----------------------------------------------------------------------------
504 wxMonoTheme::wxMonoTheme()
508 m_artProvider
= NULL
;
511 wxMonoTheme::~wxMonoTheme()
515 wxArtProvider::RemoveProvider(m_artProvider
);
518 wxRenderer
*wxMonoTheme::GetRenderer()
522 m_renderer
= new wxMonoRenderer(GetColourScheme());
528 wxArtProvider
*wxMonoTheme::GetArtProvider()
530 if ( !m_artProvider
)
532 m_artProvider
= new wxMonoArtProvider
;
535 return m_artProvider
;
538 wxColourScheme
*wxMonoTheme::GetColourScheme()
542 m_scheme
= new wxMonoColourScheme
;
548 wxInputHandler
*wxMonoTheme::GetInputHandler(const wxString
& WXUNUSED(control
),
549 wxInputConsumer
*consumer
)
551 // no special input handlers so far
552 return consumer
->DoGetStdInputHandler(NULL
);
555 // ============================================================================
556 // wxMonoColourScheme
557 // ============================================================================
559 wxColour
wxMonoColourScheme::GetBackground(wxWindow
*win
) const
562 if ( win
->UseBgCol() )
564 // use the user specified colour
565 col
= win
->GetBackgroundColour();
568 // doesn't depend on the state
577 wxColour
wxMonoColourScheme::Get(wxMonoColourScheme::StdColour col
) const
583 case CONTROL_PRESSED
:
584 case CONTROL_CURRENT
:
586 case SCROLLBAR_PRESSED
:
590 case TITLEBAR_ACTIVE
:
596 wxFAIL_MSG(_T("invalid standard colour"));
600 case SHADOW_HIGHLIGHT
:
604 case CONTROL_TEXT_DISABLED
:
605 case CONTROL_TEXT_DISABLED_SHADOW
:
608 case TITLEBAR_ACTIVE_TEXT
:
614 // ============================================================================
616 // ============================================================================
618 // ----------------------------------------------------------------------------
620 // ----------------------------------------------------------------------------
622 wxMonoRenderer::wxMonoRenderer(const wxColourScheme
*scheme
)
623 : wxStdRenderer(scheme
)
625 m_penFg
= wxPen(wxMONO_FG_COL
);
628 // ----------------------------------------------------------------------------
630 // ----------------------------------------------------------------------------
632 wxRect
wxMonoRenderer::GetBorderDimensions(wxBorder border
) const
637 case wxBORDER_SIMPLE
:
638 case wxBORDER_STATIC
:
639 case wxBORDER_RAISED
:
640 case wxBORDER_SUNKEN
:
644 case wxBORDER_DOUBLE
:
649 wxFAIL_MSG(_T("unknown border type"));
652 case wxBORDER_DEFAULT
:
667 void wxMonoRenderer::DrawBorder(wxDC
& dc
,
669 const wxRect
& rectTotal
,
673 wxRect rect
= rectTotal
;
677 case wxBORDER_DOUBLE
:
678 DrawSimpleBorder(dc
, &rect
);
681 case wxBORDER_SUNKEN
:
682 case wxBORDER_STATIC
:
683 case wxBORDER_RAISED
:
684 case wxBORDER_SIMPLE
:
685 DrawSimpleBorder(dc
, &rect
);
689 wxFAIL_MSG(_T("unknown border type"));
692 case wxBORDER_DEFAULT
:
701 void wxMonoRenderer::DrawButtonBorder(wxDC
& dc
,
706 DrawBorder(dc
, wxBORDER_SIMPLE
, rect
, flags
, rectIn
);
709 // ----------------------------------------------------------------------------
711 // ----------------------------------------------------------------------------
714 wxMonoRenderer::DrawHorizontalLine(wxDC
& dc
, wxCoord y
, wxCoord x1
, wxCoord x2
)
717 dc
.DrawLine(x1
, y
, x2
+ 1, y
);
721 wxMonoRenderer::DrawVerticalLine(wxDC
& dc
, wxCoord x
, wxCoord y1
, wxCoord y2
)
724 dc
.DrawLine(x
, y1
, x
, y2
+ 1);
727 // ----------------------------------------------------------------------------
729 // ----------------------------------------------------------------------------
731 void wxMonoRenderer::DrawButtonLabel(wxDC
& dc
,
732 const wxString
& label
,
733 const wxBitmap
& image
,
740 dc
.SetTextForeground(m_penFg
.GetColour());
741 dc
.DrawLabel(label
, image
, rect
, alignment
, indexAccel
, rectBounds
);
743 if ( flags
& wxCONTROL_DISABLED
)
745 // this is ugly but I don't know how to show disabled button visually
746 // in monochrome theme otherwise, so cross it out
748 dc
.DrawLine(rect
.GetTopLeft(), rect
.GetBottomRight());
749 dc
.DrawLine(rect
.GetTopRight(), rect
.GetBottomLeft());
753 // ----------------------------------------------------------------------------
755 // ----------------------------------------------------------------------------
757 wxBitmap
wxMonoRenderer::GetIndicator(IndicatorType indType
, int flags
)
759 IndicatorState indState
;
760 IndicatorStatus indStatus
;
761 GetIndicatorsFromFlags(flags
, indState
, indStatus
);
763 wxBitmap
& bmp
= m_bmpIndicators
[indType
][indState
][indStatus
];
766 const char **xpm
= ms_xpmIndicators
[indType
][indState
][indStatus
];
769 // create and cache it
777 wxBitmap
wxMonoRenderer::GetFrameButtonBitmap(FrameButtonType type
)
779 if ( type
== FrameButton_Close
)
781 if ( !m_bmpFrameClose
.Ok() )
783 static const char *xpmFrameClose
[] = {
784 /* columns rows colors chars-per-pixel */
799 m_bmpFrameClose
= wxBitmap(xpmFrameClose
);
802 return m_bmpFrameClose
;
805 // we don't show any other buttons than close
809 // ----------------------------------------------------------------------------
811 // ----------------------------------------------------------------------------
815 void wxMonoRenderer::DrawToolBarButton(wxDC
& dc
,
816 const wxString
& label
,
817 const wxBitmap
& bitmap
,
823 wxFAIL_MSG(_T("TODO"));
826 wxSize
wxMonoRenderer::GetToolBarButtonSize(wxCoord
*separator
) const
828 wxFAIL_MSG(_T("TODO"));
833 wxSize
wxMonoRenderer::GetToolBarMargin() const
835 wxFAIL_MSG(_T("TODO"));
840 #endif // wxUSE_TOOLBAR
842 // ----------------------------------------------------------------------------
844 // ----------------------------------------------------------------------------
848 void wxMonoRenderer::DrawTab(wxDC
& dc
,
851 const wxString
& label
,
852 const wxBitmap
& bitmap
,
856 wxFAIL_MSG(_T("TODO"));
859 wxSize
wxMonoRenderer::GetTabIndent() const
861 wxFAIL_MSG(_T("TODO"));
866 wxSize
wxMonoRenderer::GetTabPadding() const
868 wxFAIL_MSG(_T("TODO"));
873 #endif // wxUSE_NOTEBOOK
875 // ----------------------------------------------------------------------------
877 // ----------------------------------------------------------------------------
881 void wxMonoRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
883 wxBitmap
*bmpPressed
,
884 wxBitmap
*bmpDisabled
)
886 wxFAIL_MSG(_T("TODO"));
889 #endif // wxUSE_COMBOBOX
891 // ----------------------------------------------------------------------------
893 // ----------------------------------------------------------------------------
897 void wxMonoRenderer::DrawMenuBarItem(wxDC
& dc
,
899 const wxString
& label
,
903 wxFAIL_MSG(_T("TODO"));
906 void wxMonoRenderer::DrawMenuItem(wxDC
& dc
,
908 const wxMenuGeometryInfo
& geometryInfo
,
909 const wxString
& label
,
910 const wxString
& accel
,
911 const wxBitmap
& bitmap
,
915 wxFAIL_MSG(_T("TODO"));
918 void wxMonoRenderer::DrawMenuSeparator(wxDC
& dc
,
920 const wxMenuGeometryInfo
& geomInfo
)
922 wxFAIL_MSG(_T("TODO"));
925 wxSize
wxMonoRenderer::GetMenuBarItemSize(const wxSize
& sizeText
) const
927 wxFAIL_MSG(_T("TODO"));
932 wxMenuGeometryInfo
*wxMonoRenderer::GetMenuGeometry(wxWindow
*win
,
933 const wxMenu
& menu
) const
935 wxFAIL_MSG(_T("TODO"));
940 #endif // wxUSE_MENUS
942 // ----------------------------------------------------------------------------
944 // ----------------------------------------------------------------------------
948 void wxMonoRenderer::DrawSliderShaft(wxDC
& dc
,
951 wxOrientation orient
,
956 wxFAIL_MSG(_T("TODO"));
960 void wxMonoRenderer::DrawSliderThumb(wxDC
& dc
,
962 wxOrientation orient
,
966 wxFAIL_MSG(_T("TODO"));
969 void wxMonoRenderer::DrawSliderTicks(wxDC
& dc
,
972 wxOrientation orient
,
979 wxFAIL_MSG(_T("TODO"));
982 wxCoord
wxMonoRenderer::GetSliderDim() const
984 wxFAIL_MSG(_T("TODO"));
989 wxCoord
wxMonoRenderer::GetSliderTickLen() const
991 wxFAIL_MSG(_T("TODO"));
997 wxRect
wxMonoRenderer::GetSliderShaftRect(const wxRect
& rect
,
999 wxOrientation orient
,
1002 wxFAIL_MSG(_T("TODO"));
1007 wxSize
wxMonoRenderer::GetSliderThumbSize(const wxRect
& rect
,
1009 wxOrientation orient
) const
1011 wxFAIL_MSG(_T("TODO"));
1016 #endif // wxUSE_SLIDER
1018 wxSize
wxMonoRenderer::GetProgressBarStep() const
1020 wxFAIL_MSG(_T("TODO"));
1026 // ----------------------------------------------------------------------------
1028 // ----------------------------------------------------------------------------
1030 void wxMonoRenderer::DrawArrow(wxDC
& dc
,
1033 int WXUNUSED(flags
))
1035 ArrowDirection arrowDir
= GetArrowDirection(dir
);
1036 wxCHECK_RET( arrowDir
!= Arrow_Max
, _T("invalid arrow direction") );
1038 wxBitmap
& bmp
= m_bmpArrows
[arrowDir
];
1041 bmp
= wxBitmap(ms_xpmArrows
[arrowDir
]);
1044 wxRect
rectArrow(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
1045 dc
.DrawBitmap(bmp
, rectArrow
.CentreIn(rect
).GetPosition(), true /* use mask */);
1048 void wxMonoRenderer::DrawScrollbarThumb(wxDC
& dc
,
1049 wxOrientation
WXUNUSED(orient
),
1051 int WXUNUSED(flags
))
1053 DrawSolidRect(dc
, wxMONO_FG_COL
, rect
);
1056 void wxMonoRenderer::DrawScrollbarShaft(wxDC
& dc
,
1057 wxOrientation
WXUNUSED(orient
),
1059 int WXUNUSED(flags
))
1061 DrawSolidRect(dc
, wxMONO_BG_COL
, rect
);
1064 // ----------------------------------------------------------------------------
1065 // top level windows
1066 // ----------------------------------------------------------------------------
1069 // ----------------------------------------------------------------------------
1070 // wxMonoArtProvider
1071 // ----------------------------------------------------------------------------
1073 wxBitmap
wxMonoArtProvider::CreateBitmap(const wxArtID
& WXUNUSED(id
),
1074 const wxArtClient
& WXUNUSED(client
),
1075 const wxSize
& WXUNUSED(size
))
1077 return wxNullBitmap
;