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 DrawButtonBorder(wxDC
& dc
,
64 wxRect
*rectIn
= NULL
);
66 virtual void DrawHorizontalLine(wxDC
& dc
,
67 wxCoord y
, wxCoord x1
, wxCoord x2
);
69 virtual void DrawVerticalLine(wxDC
& dc
,
70 wxCoord x
, wxCoord y1
, wxCoord y2
);
72 virtual void DrawArrow(wxDC
& dc
,
76 virtual void DrawScrollbarThumb(wxDC
& dc
,
80 virtual void DrawScrollbarShaft(wxDC
& dc
,
86 virtual void DrawToolBarButton(wxDC
& dc
,
87 const wxString
& label
,
88 const wxBitmap
& bitmap
,
93 #endif // wxUSE_TOOLBAR
96 virtual void DrawTab(wxDC
& dc
,
99 const wxString
& label
,
100 const wxBitmap
& bitmap
= wxNullBitmap
,
102 int indexAccel
= -1);
103 #endif // wxUSE_NOTEBOOK
106 virtual void DrawSliderShaft(wxDC
& dc
,
109 wxOrientation orient
,
112 wxRect
*rectShaft
= NULL
);
114 virtual void DrawSliderThumb(wxDC
& dc
,
116 wxOrientation orient
,
120 virtual void DrawSliderTicks(wxDC
& dc
,
123 wxOrientation orient
,
129 #endif // wxUSE_SLIDER
132 virtual void DrawMenuBarItem(wxDC
& dc
,
134 const wxString
& label
,
136 int indexAccel
= -1);
138 virtual void DrawMenuItem(wxDC
& dc
,
140 const wxMenuGeometryInfo
& geometryInfo
,
141 const wxString
& label
,
142 const wxString
& accel
,
143 const wxBitmap
& bitmap
= wxNullBitmap
,
145 int indexAccel
= -1);
147 virtual void DrawMenuSeparator(wxDC
& dc
,
149 const wxMenuGeometryInfo
& geomInfo
);
150 #endif // wxUSE_MENUS
153 virtual void GetComboBitmaps(wxBitmap
*bmpNormal
,
155 wxBitmap
*bmpPressed
,
156 wxBitmap
*bmpDisabled
);
157 #endif // wxUSE_COMBOBOX
160 virtual wxRect
GetBorderDimensions(wxBorder border
) const;
163 virtual wxSize
GetScrollbarArrowSize() const { return GetStdBmpSize(); }
164 #endif // wxUSE_SCROLLBAR
166 virtual wxSize
GetCheckBitmapSize() const { return GetStdBmpSize(); }
167 virtual wxSize
GetRadioBitmapSize() const { return GetStdBmpSize(); }
170 virtual wxSize
GetToolBarButtonSize(wxCoord
*separator
) const;
172 virtual wxSize
GetToolBarMargin() const;
173 #endif // wxUSE_TOOLBAR
176 virtual wxSize
GetTabIndent() const;
178 virtual wxSize
GetTabPadding() const;
179 #endif // wxUSE_NOTEBOOK
182 virtual wxCoord
GetSliderDim() const;
184 virtual wxCoord
GetSliderTickLen() const;
186 virtual wxRect
GetSliderShaftRect(const wxRect
& rect
,
188 wxOrientation orient
,
189 long style
= 0) const;
191 virtual wxSize
GetSliderThumbSize(const wxRect
& rect
,
193 wxOrientation orient
) const;
194 #endif // wxUSE_SLIDER
196 virtual wxSize
GetProgressBarStep() const;
199 virtual wxSize
GetMenuBarItemSize(const wxSize
& sizeText
) const;
201 virtual wxMenuGeometryInfo
*GetMenuGeometry(wxWindow
*win
,
202 const wxMenu
& menu
) const;
203 #endif // wxUSE_MENUS
206 // override base class border drawing routines: we always draw just a
207 // single simple border
208 void DrawSimpleBorder(wxDC
& dc
, wxRect
*rect
)
209 { DrawRect(dc
, rect
, m_penFg
); }
211 virtual void DrawRaisedBorder(wxDC
& dc
, wxRect
*rect
)
212 { DrawSimpleBorder(dc
, rect
); }
213 virtual void DrawSunkenBorder(wxDC
& dc
, wxRect
*rect
)
214 { DrawSimpleBorder(dc
, rect
); }
215 virtual void DrawAntiSunkenBorder(wxDC
& dc
, wxRect
*rect
)
216 { DrawSimpleBorder(dc
, rect
); }
217 virtual void DrawBoxBorder(wxDC
& dc
, wxRect
*rect
)
218 { DrawSimpleBorder(dc
, rect
); }
219 virtual void DrawStaticBorder(wxDC
& dc
, wxRect
*rect
)
220 { DrawSimpleBorder(dc
, rect
); }
221 virtual void DrawExtraBorder(wxDC
& WXUNUSED(dc
), wxRect
* WXUNUSED(rect
))
222 { /* no extra borders for us */ }
224 // all our XPMs are of this size
225 static wxSize
GetStdBmpSize() { return wxSize(8, 8); }
227 wxBitmap
GetIndicator(IndicatorType indType
, int flags
);
228 virtual wxBitmap
GetCheckBitmap(int flags
)
229 { return GetIndicator(IndicatorType_Check
, flags
); }
230 virtual wxBitmap
GetRadioBitmap(int flags
)
231 { return GetIndicator(IndicatorType_Radio
, flags
); }
233 virtual wxBitmap
GetFrameButtonBitmap(FrameButtonType type
);
236 // the bitmaps returned by GetIndicator()
237 wxBitmap m_bmpIndicators
[IndicatorType_MaxCtrl
]
238 [IndicatorState_MaxCtrl
]
239 [IndicatorStatus_Max
];
241 static const char **ms_xpmIndicators
[IndicatorType_MaxCtrl
]
242 [IndicatorState_MaxCtrl
]
243 [IndicatorStatus_Max
];
245 // the arrow bitmaps used by DrawArrow()
246 wxBitmap m_bmpArrows
[Arrow_Max
];
248 static const char **ms_xpmArrows
[Arrow_Max
];
250 // the close bitmap for the frame for GetFrameButtonBitmap()
251 wxBitmap m_bmpFrameClose
;
253 // pen used for foreground drawing
257 // ----------------------------------------------------------------------------
259 // ----------------------------------------------------------------------------
261 static const char *xpmUnchecked
[] = {
262 /* columns rows colors chars-per-pixel */
277 static const char *xpmChecked
[] = {
278 /* columns rows colors chars-per-pixel */
293 static const char *xpmUndeterminate
[] = {
294 /* columns rows colors chars-per-pixel */
309 static const char *xpmRadioUnchecked
[] = {
310 /* columns rows colors chars-per-pixel */
325 static const char *xpmRadioChecked
[] = {
326 /* columns rows colors chars-per-pixel */
341 const char **wxMonoRenderer::ms_xpmIndicators
[IndicatorType_MaxCtrl
]
342 [IndicatorState_MaxCtrl
]
343 [IndicatorStatus_Max
] =
348 { xpmChecked
, xpmUnchecked
, xpmUndeterminate
},
351 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
354 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
360 { xpmRadioChecked
, xpmRadioUnchecked
, xpmUndeterminate
},
363 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
366 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
370 static const char *xpmLeftArrow
[] = {
371 /* columns rows colors chars-per-pixel */
386 static const char *xpmRightArrow
[] = {
387 /* columns rows colors chars-per-pixel */
402 static const char *xpmUpArrow
[] = {
403 /* columns rows colors chars-per-pixel */
418 static const char *xpmDownArrow
[] = {
419 /* columns rows colors chars-per-pixel */
434 const char **wxMonoRenderer::ms_xpmArrows
[Arrow_Max
] =
436 xpmLeftArrow
, xpmRightArrow
, xpmUpArrow
, xpmDownArrow
,
439 // ----------------------------------------------------------------------------
440 // wxMonoColourScheme: uses just white and black
441 // ----------------------------------------------------------------------------
443 class wxMonoColourScheme
: public wxColourScheme
446 // we use only 2 colours, white and black, but we avoid referring to them
447 // like this, instead use the functions below
448 wxColour
GetFg() const { return wxMONO_FG_COL
; }
449 wxColour
GetBg() const { return wxMONO_BG_COL
; }
451 // implement base class pure virtuals
452 virtual wxColour
Get(StdColour col
) const;
453 virtual wxColour
GetBackground(wxWindow
*win
) const;
456 // ----------------------------------------------------------------------------
458 // ----------------------------------------------------------------------------
460 class wxMonoArtProvider
: public wxArtProvider
463 virtual wxBitmap
CreateBitmap(const wxArtID
& id
,
464 const wxArtClient
& client
,
468 // ----------------------------------------------------------------------------
470 // ----------------------------------------------------------------------------
472 class wxMonoTheme
: public wxTheme
476 virtual ~wxMonoTheme();
478 virtual wxRenderer
*GetRenderer();
479 virtual wxArtProvider
*GetArtProvider();
480 virtual wxInputHandler
*GetInputHandler(const wxString
& control
,
481 wxInputConsumer
*consumer
);
482 virtual wxColourScheme
*GetColourScheme();
485 wxMonoRenderer
*m_renderer
;
486 wxMonoArtProvider
*m_artProvider
;
487 wxMonoColourScheme
*m_scheme
;
489 WX_DECLARE_THEME(mono
)
492 // ============================================================================
494 // ============================================================================
496 WX_IMPLEMENT_THEME(wxMonoTheme
, mono
, wxTRANSLATE("Simple monochrome theme"));
498 // ----------------------------------------------------------------------------
500 // ----------------------------------------------------------------------------
502 wxMonoTheme::wxMonoTheme()
506 m_artProvider
= NULL
;
509 wxMonoTheme::~wxMonoTheme()
513 wxArtProvider::RemoveProvider(m_artProvider
);
516 wxRenderer
*wxMonoTheme::GetRenderer()
520 m_renderer
= new wxMonoRenderer(GetColourScheme());
526 wxArtProvider
*wxMonoTheme::GetArtProvider()
528 if ( !m_artProvider
)
530 m_artProvider
= new wxMonoArtProvider
;
533 return m_artProvider
;
536 wxColourScheme
*wxMonoTheme::GetColourScheme()
540 m_scheme
= new wxMonoColourScheme
;
546 wxInputHandler
*wxMonoTheme::GetInputHandler(const wxString
& WXUNUSED(control
),
547 wxInputConsumer
*consumer
)
549 // no special input handlers so far
550 return consumer
->DoGetStdInputHandler(NULL
);
553 // ============================================================================
554 // wxMonoColourScheme
555 // ============================================================================
557 wxColour
wxMonoColourScheme::GetBackground(wxWindow
*win
) const
560 if ( win
->UseBgCol() )
562 // use the user specified colour
563 col
= win
->GetBackgroundColour();
566 // doesn't depend on the state
575 wxColour
wxMonoColourScheme::Get(wxMonoColourScheme::StdColour col
) const
581 case CONTROL_PRESSED
:
582 case CONTROL_CURRENT
:
584 case SCROLLBAR_PRESSED
:
588 case TITLEBAR_ACTIVE
:
594 wxFAIL_MSG(_T("invalid standard colour"));
598 case SHADOW_HIGHLIGHT
:
602 case CONTROL_TEXT_DISABLED
:
603 case CONTROL_TEXT_DISABLED_SHADOW
:
606 case TITLEBAR_ACTIVE_TEXT
:
612 // ============================================================================
614 // ============================================================================
616 // ----------------------------------------------------------------------------
618 // ----------------------------------------------------------------------------
620 wxMonoRenderer::wxMonoRenderer(const wxColourScheme
*scheme
)
621 : wxStdRenderer(scheme
)
623 m_penFg
= wxPen(wxMONO_FG_COL
);
626 // ----------------------------------------------------------------------------
628 // ----------------------------------------------------------------------------
630 wxRect
wxMonoRenderer::GetBorderDimensions(wxBorder border
) const
635 case wxBORDER_SIMPLE
:
636 case wxBORDER_STATIC
:
637 case wxBORDER_RAISED
:
638 case wxBORDER_SUNKEN
:
642 case wxBORDER_DOUBLE
:
647 wxFAIL_MSG(_T("unknown border type"));
650 case wxBORDER_DEFAULT
:
665 void wxMonoRenderer::DrawButtonBorder(wxDC
& dc
,
670 DrawBorder(dc
, wxBORDER_SIMPLE
, rect
, flags
, rectIn
);
673 // ----------------------------------------------------------------------------
675 // ----------------------------------------------------------------------------
678 wxMonoRenderer::DrawHorizontalLine(wxDC
& dc
, wxCoord y
, wxCoord x1
, wxCoord x2
)
681 dc
.DrawLine(x1
, y
, x2
+ 1, y
);
685 wxMonoRenderer::DrawVerticalLine(wxDC
& dc
, wxCoord x
, wxCoord y1
, wxCoord y2
)
688 dc
.DrawLine(x
, y1
, x
, y2
+ 1);
691 // ----------------------------------------------------------------------------
693 // ----------------------------------------------------------------------------
695 void wxMonoRenderer::DrawButtonLabel(wxDC
& dc
,
696 const wxString
& label
,
697 const wxBitmap
& image
,
704 dc
.SetTextForeground(m_penFg
.GetColour());
705 dc
.DrawLabel(label
, image
, rect
, alignment
, indexAccel
, rectBounds
);
707 if ( flags
& wxCONTROL_DISABLED
)
709 // this is ugly but I don't know how to show disabled button visually
710 // in monochrome theme otherwise, so cross it out
712 dc
.DrawLine(rect
.GetTopLeft(), rect
.GetBottomRight());
713 dc
.DrawLine(rect
.GetTopRight(), rect
.GetBottomLeft());
717 // ----------------------------------------------------------------------------
719 // ----------------------------------------------------------------------------
721 wxBitmap
wxMonoRenderer::GetIndicator(IndicatorType indType
, int flags
)
723 IndicatorState indState
;
724 IndicatorStatus indStatus
;
725 GetIndicatorsFromFlags(flags
, indState
, indStatus
);
727 wxBitmap
& bmp
= m_bmpIndicators
[indType
][indState
][indStatus
];
730 const char **xpm
= ms_xpmIndicators
[indType
][indState
][indStatus
];
733 // create and cache it
741 wxBitmap
wxMonoRenderer::GetFrameButtonBitmap(FrameButtonType type
)
743 if ( type
== FrameButton_Close
)
745 if ( !m_bmpFrameClose
.Ok() )
747 static const char *xpmFrameClose
[] = {
748 /* columns rows colors chars-per-pixel */
763 m_bmpFrameClose
= wxBitmap(xpmFrameClose
);
766 return m_bmpFrameClose
;
769 // we don't show any other buttons than close
773 // ----------------------------------------------------------------------------
775 // ----------------------------------------------------------------------------
779 void wxMonoRenderer::DrawToolBarButton(wxDC
& dc
,
780 const wxString
& label
,
781 const wxBitmap
& bitmap
,
787 wxFAIL_MSG(_T("TODO"));
790 wxSize
wxMonoRenderer::GetToolBarButtonSize(wxCoord
*separator
) const
792 wxFAIL_MSG(_T("TODO"));
797 wxSize
wxMonoRenderer::GetToolBarMargin() const
799 wxFAIL_MSG(_T("TODO"));
804 #endif // wxUSE_TOOLBAR
806 // ----------------------------------------------------------------------------
808 // ----------------------------------------------------------------------------
812 void wxMonoRenderer::DrawTab(wxDC
& dc
,
815 const wxString
& label
,
816 const wxBitmap
& bitmap
,
820 wxFAIL_MSG(_T("TODO"));
823 wxSize
wxMonoRenderer::GetTabIndent() const
825 wxFAIL_MSG(_T("TODO"));
830 wxSize
wxMonoRenderer::GetTabPadding() const
832 wxFAIL_MSG(_T("TODO"));
837 #endif // wxUSE_NOTEBOOK
839 // ----------------------------------------------------------------------------
841 // ----------------------------------------------------------------------------
845 void wxMonoRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
847 wxBitmap
*bmpPressed
,
848 wxBitmap
*bmpDisabled
)
850 wxFAIL_MSG(_T("TODO"));
853 #endif // wxUSE_COMBOBOX
855 // ----------------------------------------------------------------------------
857 // ----------------------------------------------------------------------------
861 void wxMonoRenderer::DrawMenuBarItem(wxDC
& dc
,
863 const wxString
& label
,
867 wxFAIL_MSG(_T("TODO"));
870 void wxMonoRenderer::DrawMenuItem(wxDC
& dc
,
872 const wxMenuGeometryInfo
& geometryInfo
,
873 const wxString
& label
,
874 const wxString
& accel
,
875 const wxBitmap
& bitmap
,
879 wxFAIL_MSG(_T("TODO"));
882 void wxMonoRenderer::DrawMenuSeparator(wxDC
& dc
,
884 const wxMenuGeometryInfo
& geomInfo
)
886 wxFAIL_MSG(_T("TODO"));
889 wxSize
wxMonoRenderer::GetMenuBarItemSize(const wxSize
& sizeText
) const
891 wxFAIL_MSG(_T("TODO"));
896 wxMenuGeometryInfo
*wxMonoRenderer::GetMenuGeometry(wxWindow
*win
,
897 const wxMenu
& menu
) const
899 wxFAIL_MSG(_T("TODO"));
904 #endif // wxUSE_MENUS
906 // ----------------------------------------------------------------------------
908 // ----------------------------------------------------------------------------
912 void wxMonoRenderer::DrawSliderShaft(wxDC
& dc
,
915 wxOrientation orient
,
920 wxFAIL_MSG(_T("TODO"));
924 void wxMonoRenderer::DrawSliderThumb(wxDC
& dc
,
926 wxOrientation orient
,
930 wxFAIL_MSG(_T("TODO"));
933 void wxMonoRenderer::DrawSliderTicks(wxDC
& dc
,
936 wxOrientation orient
,
943 wxFAIL_MSG(_T("TODO"));
946 wxCoord
wxMonoRenderer::GetSliderDim() const
948 wxFAIL_MSG(_T("TODO"));
953 wxCoord
wxMonoRenderer::GetSliderTickLen() const
955 wxFAIL_MSG(_T("TODO"));
961 wxRect
wxMonoRenderer::GetSliderShaftRect(const wxRect
& rect
,
963 wxOrientation orient
,
966 wxFAIL_MSG(_T("TODO"));
971 wxSize
wxMonoRenderer::GetSliderThumbSize(const wxRect
& rect
,
973 wxOrientation orient
) const
975 wxFAIL_MSG(_T("TODO"));
980 #endif // wxUSE_SLIDER
982 wxSize
wxMonoRenderer::GetProgressBarStep() const
984 wxFAIL_MSG(_T("TODO"));
990 // ----------------------------------------------------------------------------
992 // ----------------------------------------------------------------------------
994 void wxMonoRenderer::DrawArrow(wxDC
& dc
,
999 ArrowDirection arrowDir
= GetArrowDirection(dir
);
1000 wxCHECK_RET( arrowDir
!= Arrow_Max
, _T("invalid arrow direction") );
1002 wxBitmap
& bmp
= m_bmpArrows
[arrowDir
];
1005 bmp
= wxBitmap(ms_xpmArrows
[arrowDir
]);
1008 wxRect
rectArrow(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
1009 dc
.DrawBitmap(bmp
, rectArrow
.CentreIn(rect
).GetPosition(), true /* use mask */);
1012 void wxMonoRenderer::DrawScrollbarThumb(wxDC
& dc
,
1013 wxOrientation
WXUNUSED(orient
),
1015 int WXUNUSED(flags
))
1017 DrawSolidRect(dc
, wxMONO_FG_COL
, rect
);
1020 void wxMonoRenderer::DrawScrollbarShaft(wxDC
& dc
,
1021 wxOrientation
WXUNUSED(orient
),
1023 int WXUNUSED(flags
))
1025 DrawSolidRect(dc
, wxMONO_BG_COL
, rect
);
1028 // ----------------------------------------------------------------------------
1029 // top level windows
1030 // ----------------------------------------------------------------------------
1033 // ----------------------------------------------------------------------------
1034 // wxMonoArtProvider
1035 // ----------------------------------------------------------------------------
1037 wxBitmap
wxMonoArtProvider::CreateBitmap(const wxArtID
& WXUNUSED(id
),
1038 const wxArtClient
& WXUNUSED(client
),
1039 const wxSize
& WXUNUSED(size
))
1041 return wxNullBitmap
;