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
);
235 virtual int GetFrameBorderWidth(int flags
) const;
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 delete 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
:
589 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
:
607 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::DrawButtonBorder(wxDC
& dc
,
672 DrawBorder(dc
, wxBORDER_SIMPLE
, rect
, flags
, rectIn
);
675 // ----------------------------------------------------------------------------
677 // ----------------------------------------------------------------------------
680 wxMonoRenderer::DrawHorizontalLine(wxDC
& dc
, wxCoord y
, wxCoord x1
, wxCoord x2
)
683 dc
.DrawLine(x1
, y
, x2
+ 1, y
);
687 wxMonoRenderer::DrawVerticalLine(wxDC
& dc
, wxCoord x
, wxCoord y1
, wxCoord y2
)
690 dc
.DrawLine(x
, y1
, x
, y2
+ 1);
693 // ----------------------------------------------------------------------------
695 // ----------------------------------------------------------------------------
697 void wxMonoRenderer::DrawButtonLabel(wxDC
& dc
,
698 const wxString
& label
,
699 const wxBitmap
& image
,
706 dc
.SetTextForeground(m_penFg
.GetColour());
707 dc
.DrawLabel(label
, image
, rect
, alignment
, indexAccel
, rectBounds
);
709 if ( flags
& wxCONTROL_DISABLED
)
711 // this is ugly but I don't know how to show disabled button visually
712 // in monochrome theme otherwise, so cross it out
714 dc
.DrawLine(rect
.GetTopLeft(), rect
.GetBottomRight());
715 dc
.DrawLine(rect
.GetTopRight(), rect
.GetBottomLeft());
719 // ----------------------------------------------------------------------------
721 // ----------------------------------------------------------------------------
723 wxBitmap
wxMonoRenderer::GetIndicator(IndicatorType indType
, int flags
)
725 IndicatorState indState
;
726 IndicatorStatus indStatus
;
727 GetIndicatorsFromFlags(flags
, indState
, indStatus
);
729 wxBitmap
& bmp
= m_bmpIndicators
[indType
][indState
][indStatus
];
732 const char **xpm
= ms_xpmIndicators
[indType
][indState
][indStatus
];
735 // create and cache it
743 wxBitmap
wxMonoRenderer::GetFrameButtonBitmap(FrameButtonType type
)
745 if ( type
== FrameButton_Close
)
747 if ( !m_bmpFrameClose
.Ok() )
749 static const char *xpmFrameClose
[] = {
750 /* columns rows colors chars-per-pixel */
765 m_bmpFrameClose
= wxBitmap(xpmFrameClose
);
768 return m_bmpFrameClose
;
771 // we don't show any other buttons than close
775 // ----------------------------------------------------------------------------
777 // ----------------------------------------------------------------------------
781 void wxMonoRenderer::DrawToolBarButton(wxDC
& dc
,
782 const wxString
& label
,
783 const wxBitmap
& bitmap
,
789 wxFAIL_MSG(_T("TODO"));
792 wxSize
wxMonoRenderer::GetToolBarButtonSize(wxCoord
*separator
) const
794 wxFAIL_MSG(_T("TODO"));
799 wxSize
wxMonoRenderer::GetToolBarMargin() const
801 wxFAIL_MSG(_T("TODO"));
806 #endif // wxUSE_TOOLBAR
808 // ----------------------------------------------------------------------------
810 // ----------------------------------------------------------------------------
814 void wxMonoRenderer::DrawTab(wxDC
& dc
,
817 const wxString
& label
,
818 const wxBitmap
& bitmap
,
822 wxFAIL_MSG(_T("TODO"));
825 wxSize
wxMonoRenderer::GetTabIndent() const
827 wxFAIL_MSG(_T("TODO"));
832 wxSize
wxMonoRenderer::GetTabPadding() const
834 wxFAIL_MSG(_T("TODO"));
839 #endif // wxUSE_NOTEBOOK
841 // ----------------------------------------------------------------------------
843 // ----------------------------------------------------------------------------
847 void wxMonoRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
849 wxBitmap
*bmpPressed
,
850 wxBitmap
*bmpDisabled
)
852 wxFAIL_MSG(_T("TODO"));
855 #endif // wxUSE_COMBOBOX
857 // ----------------------------------------------------------------------------
859 // ----------------------------------------------------------------------------
863 void wxMonoRenderer::DrawMenuBarItem(wxDC
& dc
,
865 const wxString
& label
,
869 wxFAIL_MSG(_T("TODO"));
872 void wxMonoRenderer::DrawMenuItem(wxDC
& dc
,
874 const wxMenuGeometryInfo
& geometryInfo
,
875 const wxString
& label
,
876 const wxString
& accel
,
877 const wxBitmap
& bitmap
,
881 wxFAIL_MSG(_T("TODO"));
884 void wxMonoRenderer::DrawMenuSeparator(wxDC
& dc
,
886 const wxMenuGeometryInfo
& geomInfo
)
888 wxFAIL_MSG(_T("TODO"));
891 wxSize
wxMonoRenderer::GetMenuBarItemSize(const wxSize
& sizeText
) const
893 wxFAIL_MSG(_T("TODO"));
898 wxMenuGeometryInfo
*wxMonoRenderer::GetMenuGeometry(wxWindow
*win
,
899 const wxMenu
& menu
) const
901 wxFAIL_MSG(_T("TODO"));
906 #endif // wxUSE_MENUS
908 // ----------------------------------------------------------------------------
910 // ----------------------------------------------------------------------------
914 void wxMonoRenderer::DrawSliderShaft(wxDC
& dc
,
917 wxOrientation orient
,
922 wxFAIL_MSG(_T("TODO"));
926 void wxMonoRenderer::DrawSliderThumb(wxDC
& dc
,
928 wxOrientation orient
,
932 wxFAIL_MSG(_T("TODO"));
935 void wxMonoRenderer::DrawSliderTicks(wxDC
& dc
,
938 wxOrientation orient
,
945 wxFAIL_MSG(_T("TODO"));
948 wxCoord
wxMonoRenderer::GetSliderDim() const
950 wxFAIL_MSG(_T("TODO"));
955 wxCoord
wxMonoRenderer::GetSliderTickLen() const
957 wxFAIL_MSG(_T("TODO"));
963 wxRect
wxMonoRenderer::GetSliderShaftRect(const wxRect
& rect
,
965 wxOrientation orient
,
968 wxFAIL_MSG(_T("TODO"));
973 wxSize
wxMonoRenderer::GetSliderThumbSize(const wxRect
& rect
,
975 wxOrientation orient
) const
977 wxFAIL_MSG(_T("TODO"));
982 #endif // wxUSE_SLIDER
984 wxSize
wxMonoRenderer::GetProgressBarStep() const
986 wxFAIL_MSG(_T("TODO"));
992 // ----------------------------------------------------------------------------
994 // ----------------------------------------------------------------------------
996 void wxMonoRenderer::DrawArrow(wxDC
& dc
,
1001 ArrowDirection arrowDir
= GetArrowDirection(dir
);
1002 wxCHECK_RET( arrowDir
!= Arrow_Max
, _T("invalid arrow direction") );
1004 wxBitmap
& bmp
= m_bmpArrows
[arrowDir
];
1007 bmp
= wxBitmap(ms_xpmArrows
[arrowDir
]);
1010 wxRect
rectArrow(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
1011 dc
.DrawBitmap(bmp
, rectArrow
.CentreIn(rect
).GetPosition(), true /* use mask */);
1014 void wxMonoRenderer::DrawScrollbarThumb(wxDC
& dc
,
1015 wxOrientation
WXUNUSED(orient
),
1017 int WXUNUSED(flags
))
1019 DrawSolidRect(dc
, wxMONO_FG_COL
, rect
);
1022 void wxMonoRenderer::DrawScrollbarShaft(wxDC
& dc
,
1023 wxOrientation
WXUNUSED(orient
),
1025 int WXUNUSED(flags
))
1027 DrawSolidRect(dc
, wxMONO_BG_COL
, rect
);
1030 // ----------------------------------------------------------------------------
1031 // top level windows
1032 // ----------------------------------------------------------------------------
1034 int wxMonoRenderer::GetFrameBorderWidth(int WXUNUSED(flags
)) const
1036 // all our borders are simple
1040 // ----------------------------------------------------------------------------
1041 // wxMonoArtProvider
1042 // ----------------------------------------------------------------------------
1044 wxBitmap
wxMonoArtProvider::CreateBitmap(const wxArtID
& WXUNUSED(id
),
1045 const wxArtClient
& WXUNUSED(client
),
1046 const wxSize
& WXUNUSED(size
))
1048 return wxNullBitmap
;