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 DrawButtonBorder(wxDC
& dc
,
68 wxRect
*rectIn
= NULL
);
70 virtual void DrawHorizontalLine(wxDC
& dc
,
71 wxCoord y
, wxCoord x1
, wxCoord x2
);
73 virtual void DrawVerticalLine(wxDC
& dc
,
74 wxCoord x
, wxCoord y1
, wxCoord y2
);
76 virtual void DrawArrow(wxDC
& dc
,
80 virtual void DrawScrollbarThumb(wxDC
& dc
,
84 virtual void DrawScrollbarShaft(wxDC
& dc
,
90 virtual void DrawToolBarButton(wxDC
& dc
,
91 const wxString
& label
,
92 const wxBitmap
& bitmap
,
97 #endif // wxUSE_TOOLBAR
100 virtual void DrawTab(wxDC
& dc
,
103 const wxString
& label
,
104 const wxBitmap
& bitmap
= wxNullBitmap
,
106 int indexAccel
= -1);
107 #endif // wxUSE_NOTEBOOK
110 virtual void DrawSliderShaft(wxDC
& dc
,
113 wxOrientation orient
,
116 wxRect
*rectShaft
= NULL
);
118 virtual void DrawSliderThumb(wxDC
& dc
,
120 wxOrientation orient
,
124 virtual void DrawSliderTicks(wxDC
& dc
,
127 wxOrientation orient
,
133 #endif // wxUSE_SLIDER
136 virtual void DrawMenuBarItem(wxDC
& dc
,
138 const wxString
& label
,
140 int indexAccel
= -1);
142 virtual void DrawMenuItem(wxDC
& dc
,
144 const wxMenuGeometryInfo
& geometryInfo
,
145 const wxString
& label
,
146 const wxString
& accel
,
147 const wxBitmap
& bitmap
= wxNullBitmap
,
149 int indexAccel
= -1);
151 virtual void DrawMenuSeparator(wxDC
& dc
,
153 const wxMenuGeometryInfo
& geomInfo
);
154 #endif // wxUSE_MENUS
157 virtual void GetComboBitmaps(wxBitmap
*bmpNormal
,
159 wxBitmap
*bmpPressed
,
160 wxBitmap
*bmpDisabled
);
161 #endif // wxUSE_COMBOBOX
164 virtual wxRect
GetBorderDimensions(wxBorder border
) const;
167 virtual wxSize
GetScrollbarArrowSize() const { return GetStdBmpSize(); }
168 #endif // wxUSE_SCROLLBAR
170 virtual wxSize
GetCheckBitmapSize() const { return GetStdBmpSize(); }
171 virtual wxSize
GetRadioBitmapSize() const { return GetStdBmpSize(); }
174 virtual wxSize
GetToolBarButtonSize(wxCoord
*separator
) const;
176 virtual wxSize
GetToolBarMargin() const;
177 #endif // wxUSE_TOOLBAR
180 virtual wxSize
GetTabIndent() const;
182 virtual wxSize
GetTabPadding() const;
183 #endif // wxUSE_NOTEBOOK
186 virtual wxCoord
GetSliderDim() const;
188 virtual wxCoord
GetSliderTickLen() const;
190 virtual wxRect
GetSliderShaftRect(const wxRect
& rect
,
192 wxOrientation orient
,
193 long style
= 0) const;
195 virtual wxSize
GetSliderThumbSize(const wxRect
& rect
,
197 wxOrientation orient
) const;
198 #endif // wxUSE_SLIDER
200 virtual wxSize
GetProgressBarStep() const;
203 virtual wxSize
GetMenuBarItemSize(const wxSize
& sizeText
) const;
205 virtual wxMenuGeometryInfo
*GetMenuGeometry(wxWindow
*win
,
206 const wxMenu
& menu
) const;
207 #endif // wxUSE_MENUS
210 virtual wxCoord
GetStatusBarBorderBetweenFields() const;
212 virtual wxSize
GetStatusBarFieldMargins() const;
213 #endif // wxUSE_STATUSBAR
216 // override base class border drawing routines: we always draw just a
217 // single simple border
218 void DrawSimpleBorder(wxDC
& dc
, wxRect
*rect
)
219 { DrawRect(dc
, rect
, m_penFg
); }
221 virtual void DrawRaisedBorder(wxDC
& dc
, wxRect
*rect
)
222 { DrawSimpleBorder(dc
, rect
); }
223 virtual void DrawSunkenBorder(wxDC
& dc
, wxRect
*rect
)
224 { DrawSimpleBorder(dc
, rect
); }
225 virtual void DrawAntiSunkenBorder(wxDC
& dc
, wxRect
*rect
)
226 { DrawSimpleBorder(dc
, rect
); }
227 virtual void DrawBoxBorder(wxDC
& dc
, wxRect
*rect
)
228 { DrawSimpleBorder(dc
, rect
); }
229 virtual void DrawStaticBorder(wxDC
& dc
, wxRect
*rect
)
230 { DrawSimpleBorder(dc
, rect
); }
231 virtual void DrawExtraBorder(wxDC
& WXUNUSED(dc
), wxRect
* WXUNUSED(rect
))
232 { /* no extra borders for us */ }
234 // all our XPMs are of this size
235 static wxSize
GetStdBmpSize() { return wxSize(8, 8); }
237 wxBitmap
GetIndicator(IndicatorType indType
, int flags
);
238 virtual wxBitmap
GetCheckBitmap(int flags
)
239 { return GetIndicator(IndicatorType_Check
, flags
); }
240 virtual wxBitmap
GetRadioBitmap(int flags
)
241 { return GetIndicator(IndicatorType_Radio
, flags
); }
243 virtual wxBitmap
GetFrameButtonBitmap(FrameButtonType type
);
244 virtual int GetFrameBorderWidth(int flags
) const;
247 // the bitmaps returned by GetIndicator()
248 wxBitmap m_bmpIndicators
[IndicatorType_MaxCtrl
]
249 [IndicatorState_MaxCtrl
]
250 [IndicatorStatus_Max
];
252 static const char **ms_xpmIndicators
[IndicatorType_MaxCtrl
]
253 [IndicatorState_MaxCtrl
]
254 [IndicatorStatus_Max
];
256 // the arrow bitmaps used by DrawArrow()
257 wxBitmap m_bmpArrows
[Arrow_Max
];
259 static const char **ms_xpmArrows
[Arrow_Max
];
261 // the close bitmap for the frame for GetFrameButtonBitmap()
262 wxBitmap m_bmpFrameClose
;
264 // pen used for foreground drawing
268 // ----------------------------------------------------------------------------
270 // ----------------------------------------------------------------------------
272 static const char *xpmUnchecked
[] = {
273 /* columns rows colors chars-per-pixel */
288 static const char *xpmChecked
[] = {
289 /* columns rows colors chars-per-pixel */
304 static const char *xpmUndeterminate
[] = {
305 /* columns rows colors chars-per-pixel */
320 static const char *xpmRadioUnchecked
[] = {
321 /* columns rows colors chars-per-pixel */
336 static const char *xpmRadioChecked
[] = {
337 /* columns rows colors chars-per-pixel */
352 const char **wxMonoRenderer::ms_xpmIndicators
[IndicatorType_MaxCtrl
]
353 [IndicatorState_MaxCtrl
]
354 [IndicatorStatus_Max
] =
359 { xpmChecked
, xpmUnchecked
, xpmUndeterminate
},
362 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
365 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
371 { xpmRadioChecked
, xpmRadioUnchecked
, xpmUndeterminate
},
374 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
377 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
381 static const char *xpmLeftArrow
[] = {
382 /* columns rows colors chars-per-pixel */
397 static const char *xpmRightArrow
[] = {
398 /* columns rows colors chars-per-pixel */
413 static const char *xpmUpArrow
[] = {
414 /* columns rows colors chars-per-pixel */
429 static const char *xpmDownArrow
[] = {
430 /* columns rows colors chars-per-pixel */
445 const char **wxMonoRenderer::ms_xpmArrows
[Arrow_Max
] =
447 xpmLeftArrow
, xpmRightArrow
, xpmUpArrow
, xpmDownArrow
,
450 // ----------------------------------------------------------------------------
451 // wxMonoColourScheme: uses just white and black
452 // ----------------------------------------------------------------------------
454 class wxMonoColourScheme
: public wxColourScheme
457 // we use only 2 colours, white and black, but we avoid referring to them
458 // like this, instead use the functions below
459 wxColour
GetFg() const { return wxMONO_FG_COL
; }
460 wxColour
GetBg() const { return wxMONO_BG_COL
; }
462 // implement base class pure virtuals
463 virtual wxColour
Get(StdColour col
) const;
464 virtual wxColour
GetBackground(wxWindow
*win
) const;
467 // ----------------------------------------------------------------------------
469 // ----------------------------------------------------------------------------
471 class wxMonoArtProvider
: public wxArtProvider
474 virtual wxBitmap
CreateBitmap(const wxArtID
& id
,
475 const wxArtClient
& client
,
479 // ----------------------------------------------------------------------------
481 // ----------------------------------------------------------------------------
483 class wxMonoTheme
: public wxTheme
487 virtual ~wxMonoTheme();
489 virtual wxRenderer
*GetRenderer();
490 virtual wxArtProvider
*GetArtProvider();
491 virtual wxInputHandler
*GetInputHandler(const wxString
& control
,
492 wxInputConsumer
*consumer
);
493 virtual wxColourScheme
*GetColourScheme();
496 wxMonoRenderer
*m_renderer
;
497 wxMonoArtProvider
*m_artProvider
;
498 wxMonoColourScheme
*m_scheme
;
500 WX_DECLARE_THEME(mono
)
503 // ============================================================================
505 // ============================================================================
507 WX_IMPLEMENT_THEME(wxMonoTheme
, mono
, wxTRANSLATE("Simple monochrome theme"));
509 // ----------------------------------------------------------------------------
511 // ----------------------------------------------------------------------------
513 wxMonoTheme::wxMonoTheme()
517 m_artProvider
= NULL
;
520 wxMonoTheme::~wxMonoTheme()
524 delete m_artProvider
;
527 wxRenderer
*wxMonoTheme::GetRenderer()
531 m_renderer
= new wxMonoRenderer(GetColourScheme());
537 wxArtProvider
*wxMonoTheme::GetArtProvider()
539 if ( !m_artProvider
)
541 m_artProvider
= new wxMonoArtProvider
;
544 return m_artProvider
;
547 wxColourScheme
*wxMonoTheme::GetColourScheme()
551 m_scheme
= new wxMonoColourScheme
;
557 wxInputHandler
*wxMonoTheme::GetInputHandler(const wxString
& WXUNUSED(control
),
558 wxInputConsumer
*consumer
)
560 // no special input handlers so far
561 return consumer
->DoGetStdInputHandler(NULL
);
564 // ============================================================================
565 // wxMonoColourScheme
566 // ============================================================================
568 wxColour
wxMonoColourScheme::GetBackground(wxWindow
*win
) const
571 if ( win
->UseBgCol() )
573 // use the user specified colour
574 col
= win
->GetBackgroundColour();
577 // doesn't depend on the state
586 wxColour
wxMonoColourScheme::Get(wxMonoColourScheme::StdColour col
) const
592 case CONTROL_PRESSED
:
593 case CONTROL_CURRENT
:
595 case SCROLLBAR_PRESSED
:
598 case TITLEBAR_ACTIVE
:
605 wxFAIL_MSG(_T("invalid standard colour"));
609 case SHADOW_HIGHLIGHT
:
613 case CONTROL_TEXT_DISABLED
:
614 case CONTROL_TEXT_DISABLED_SHADOW
:
616 case TITLEBAR_ACTIVE_TEXT
:
623 // ============================================================================
625 // ============================================================================
627 // ----------------------------------------------------------------------------
629 // ----------------------------------------------------------------------------
631 wxMonoRenderer::wxMonoRenderer(const wxColourScheme
*scheme
)
632 : wxStdRenderer(scheme
)
634 m_penFg
= wxPen(wxMONO_FG_COL
);
637 // ----------------------------------------------------------------------------
639 // ----------------------------------------------------------------------------
641 wxRect
wxMonoRenderer::GetBorderDimensions(wxBorder border
) const
646 case wxBORDER_SIMPLE
:
647 case wxBORDER_STATIC
:
648 case wxBORDER_RAISED
:
649 case wxBORDER_SUNKEN
:
653 case wxBORDER_DOUBLE
:
658 wxFAIL_MSG(_T("unknown border type"));
661 case wxBORDER_DEFAULT
:
676 void wxMonoRenderer::DrawButtonBorder(wxDC
& dc
,
681 DrawBorder(dc
, wxBORDER_SIMPLE
, rect
, flags
, rectIn
);
684 // ----------------------------------------------------------------------------
686 // ----------------------------------------------------------------------------
689 wxMonoRenderer::DrawHorizontalLine(wxDC
& dc
, wxCoord y
, wxCoord x1
, wxCoord x2
)
692 dc
.DrawLine(x1
, y
, x2
+ 1, y
);
696 wxMonoRenderer::DrawVerticalLine(wxDC
& dc
, wxCoord x
, wxCoord y1
, wxCoord y2
)
699 dc
.DrawLine(x
, y1
, x
, y2
+ 1);
702 // ----------------------------------------------------------------------------
704 // ----------------------------------------------------------------------------
706 void wxMonoRenderer::DrawButtonLabel(wxDC
& dc
,
707 const wxString
& label
,
708 const wxBitmap
& image
,
715 dc
.SetTextForeground(m_penFg
.GetColour());
716 dc
.DrawLabel(label
, image
, rect
, alignment
, indexAccel
, rectBounds
);
718 if ( flags
& wxCONTROL_DISABLED
)
720 // this is ugly but I don't know how to show disabled button visually
721 // in monochrome theme otherwise, so cross it out
723 dc
.DrawLine(rect
.GetTopLeft(), rect
.GetBottomRight());
724 dc
.DrawLine(rect
.GetTopRight(), rect
.GetBottomLeft());
728 // ----------------------------------------------------------------------------
730 // ----------------------------------------------------------------------------
732 wxBitmap
wxMonoRenderer::GetIndicator(IndicatorType indType
, int flags
)
734 IndicatorState indState
;
735 IndicatorStatus indStatus
;
736 GetIndicatorsFromFlags(flags
, indState
, indStatus
);
738 wxBitmap
& bmp
= m_bmpIndicators
[indType
][indState
][indStatus
];
741 const char **xpm
= ms_xpmIndicators
[indType
][indState
][indStatus
];
744 // create and cache it
752 wxBitmap
wxMonoRenderer::GetFrameButtonBitmap(FrameButtonType type
)
754 if ( type
== FrameButton_Close
)
756 if ( !m_bmpFrameClose
.Ok() )
758 static const char *xpmFrameClose
[] = {
759 /* columns rows colors chars-per-pixel */
774 m_bmpFrameClose
= wxBitmap(xpmFrameClose
);
777 return m_bmpFrameClose
;
780 // we don't show any other buttons than close
784 // ----------------------------------------------------------------------------
786 // ----------------------------------------------------------------------------
790 void wxMonoRenderer::DrawToolBarButton(wxDC
& dc
,
791 const wxString
& label
,
792 const wxBitmap
& bitmap
,
798 wxFAIL_MSG(_T("TODO"));
801 wxSize
wxMonoRenderer::GetToolBarButtonSize(wxCoord
*separator
) const
803 wxFAIL_MSG(_T("TODO"));
808 wxSize
wxMonoRenderer::GetToolBarMargin() const
810 wxFAIL_MSG(_T("TODO"));
815 #endif // wxUSE_TOOLBAR
817 // ----------------------------------------------------------------------------
819 // ----------------------------------------------------------------------------
823 void wxMonoRenderer::DrawTab(wxDC
& dc
,
826 const wxString
& label
,
827 const wxBitmap
& bitmap
,
831 wxFAIL_MSG(_T("TODO"));
834 wxSize
wxMonoRenderer::GetTabIndent() const
836 wxFAIL_MSG(_T("TODO"));
841 wxSize
wxMonoRenderer::GetTabPadding() const
843 wxFAIL_MSG(_T("TODO"));
848 #endif // wxUSE_NOTEBOOK
850 // ----------------------------------------------------------------------------
852 // ----------------------------------------------------------------------------
856 void wxMonoRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
858 wxBitmap
*bmpPressed
,
859 wxBitmap
*bmpDisabled
)
861 wxFAIL_MSG(_T("TODO"));
864 #endif // wxUSE_COMBOBOX
866 // ----------------------------------------------------------------------------
868 // ----------------------------------------------------------------------------
872 void wxMonoRenderer::DrawMenuBarItem(wxDC
& dc
,
874 const wxString
& label
,
878 wxFAIL_MSG(_T("TODO"));
881 void wxMonoRenderer::DrawMenuItem(wxDC
& dc
,
883 const wxMenuGeometryInfo
& geometryInfo
,
884 const wxString
& label
,
885 const wxString
& accel
,
886 const wxBitmap
& bitmap
,
890 wxFAIL_MSG(_T("TODO"));
893 void wxMonoRenderer::DrawMenuSeparator(wxDC
& dc
,
895 const wxMenuGeometryInfo
& geomInfo
)
897 wxFAIL_MSG(_T("TODO"));
900 wxSize
wxMonoRenderer::GetMenuBarItemSize(const wxSize
& sizeText
) const
902 wxFAIL_MSG(_T("TODO"));
907 wxMenuGeometryInfo
*wxMonoRenderer::GetMenuGeometry(wxWindow
*win
,
908 const wxMenu
& menu
) const
910 wxFAIL_MSG(_T("TODO"));
915 #endif // wxUSE_MENUS
917 // ----------------------------------------------------------------------------
919 // ----------------------------------------------------------------------------
923 void wxMonoRenderer::DrawSliderShaft(wxDC
& dc
,
926 wxOrientation orient
,
931 wxFAIL_MSG(_T("TODO"));
935 void wxMonoRenderer::DrawSliderThumb(wxDC
& dc
,
937 wxOrientation orient
,
941 wxFAIL_MSG(_T("TODO"));
944 void wxMonoRenderer::DrawSliderTicks(wxDC
& dc
,
947 wxOrientation orient
,
954 wxFAIL_MSG(_T("TODO"));
957 wxCoord
wxMonoRenderer::GetSliderDim() const
959 wxFAIL_MSG(_T("TODO"));
964 wxCoord
wxMonoRenderer::GetSliderTickLen() const
966 wxFAIL_MSG(_T("TODO"));
972 wxRect
wxMonoRenderer::GetSliderShaftRect(const wxRect
& rect
,
974 wxOrientation orient
,
977 wxFAIL_MSG(_T("TODO"));
982 wxSize
wxMonoRenderer::GetSliderThumbSize(const wxRect
& rect
,
984 wxOrientation orient
) const
986 wxFAIL_MSG(_T("TODO"));
991 #endif // wxUSE_SLIDER
993 wxSize
wxMonoRenderer::GetProgressBarStep() const
995 wxFAIL_MSG(_T("TODO"));
1001 // ----------------------------------------------------------------------------
1003 // ----------------------------------------------------------------------------
1005 void wxMonoRenderer::DrawArrow(wxDC
& dc
,
1008 int WXUNUSED(flags
))
1010 ArrowDirection arrowDir
= GetArrowDirection(dir
);
1011 wxCHECK_RET( arrowDir
!= Arrow_Max
, _T("invalid arrow direction") );
1013 wxBitmap
& bmp
= m_bmpArrows
[arrowDir
];
1016 bmp
= wxBitmap(ms_xpmArrows
[arrowDir
]);
1019 wxRect
rectArrow(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
1020 dc
.DrawBitmap(bmp
, rectArrow
.CentreIn(rect
).GetPosition(), true /* use mask */);
1023 void wxMonoRenderer::DrawScrollbarThumb(wxDC
& dc
,
1024 wxOrientation
WXUNUSED(orient
),
1026 int WXUNUSED(flags
))
1028 DrawSolidRect(dc
, wxMONO_FG_COL
, rect
);
1031 void wxMonoRenderer::DrawScrollbarShaft(wxDC
& dc
,
1032 wxOrientation
WXUNUSED(orient
),
1034 int WXUNUSED(flags
))
1036 DrawSolidRect(dc
, wxMONO_BG_COL
, rect
);
1039 // ----------------------------------------------------------------------------
1041 // ----------------------------------------------------------------------------
1045 wxCoord
wxMonoRenderer::GetStatusBarBorderBetweenFields() const
1050 wxSize
wxMonoRenderer::GetStatusBarFieldMargins() const
1052 return wxSize(1, 1);
1055 #endif // wxUSE_STATUSBAR
1057 // ----------------------------------------------------------------------------
1058 // top level windows
1059 // ----------------------------------------------------------------------------
1061 int wxMonoRenderer::GetFrameBorderWidth(int WXUNUSED(flags
)) const
1063 // all our borders are simple
1067 // ----------------------------------------------------------------------------
1068 // wxMonoArtProvider
1069 // ----------------------------------------------------------------------------
1071 wxBitmap
wxMonoArtProvider::CreateBitmap(const wxArtID
& WXUNUSED(id
),
1072 const wxArtClient
& WXUNUSED(client
),
1073 const wxSize
& WXUNUSED(size
))
1075 return wxNullBitmap
;
1078 #endif // wxUSE_THEME_MONO