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 DrawStatusField(wxDC
& dc
,
161 const wxString
& label
,
162 int flags
= 0, int style
= 0);
163 #endif // wxUSE_STATUSBAR
165 virtual void DrawFrameTitleBar(wxDC
& dc
,
167 const wxString
& title
,
170 int specialButton
= 0,
171 int specialButtonFlags
= 0);
173 virtual void DrawFrameBorder(wxDC
& dc
,
177 virtual void DrawFrameBackground(wxDC
& dc
,
181 virtual void DrawFrameTitle(wxDC
& dc
,
183 const wxString
& title
,
186 virtual void DrawFrameIcon(wxDC
& dc
,
191 virtual void DrawFrameButton(wxDC
& dc
,
192 wxCoord x
, wxCoord y
,
198 virtual void GetComboBitmaps(wxBitmap
*bmpNormal
,
200 wxBitmap
*bmpPressed
,
201 wxBitmap
*bmpDisabled
);
202 #endif // wxUSE_COMBOBOX
205 virtual wxRect
GetBorderDimensions(wxBorder border
) const;
207 virtual bool AreScrollbarsInsideBorder() const;
210 virtual wxSize
GetScrollbarArrowSize() const { return GetStdBmpSize(); }
211 #endif // wxUSE_SCROLLBAR
213 virtual wxCoord
GetListboxItemHeight(wxCoord fontHeight
);
215 virtual wxSize
GetCheckBitmapSize() const { return GetStdBmpSize(); }
216 virtual wxSize
GetRadioBitmapSize() const { return GetStdBmpSize(); }
218 virtual wxSize
GetToolBarButtonSize(wxCoord
*separator
) const;
220 virtual wxSize
GetToolBarMargin() const;
223 virtual wxSize
GetTabIndent() const;
225 virtual wxSize
GetTabPadding() const;
226 #endif // wxUSE_NOTEBOOK
229 virtual wxCoord
GetSliderDim() const;
231 virtual wxCoord
GetSliderTickLen() const;
233 virtual wxRect
GetSliderShaftRect(const wxRect
& rect
,
235 wxOrientation orient
,
236 long style
= 0) const;
238 virtual wxSize
GetSliderThumbSize(const wxRect
& rect
,
240 wxOrientation orient
) const;
241 #endif // wxUSE_SLIDER
243 virtual wxSize
GetProgressBarStep() const;
246 virtual wxSize
GetMenuBarItemSize(const wxSize
& sizeText
) const;
248 virtual wxMenuGeometryInfo
*GetMenuGeometry(wxWindow
*win
,
249 const wxMenu
& menu
) const;
250 #endif // wxUSE_MENUS
253 virtual wxSize
GetStatusBarBorders(wxCoord
*borderBetweenFields
) const;
254 #endif // wxUSE_STATUSBAR
256 virtual wxRect
GetFrameClientArea(const wxRect
& rect
, int flags
) const;
258 virtual wxSize
GetFrameTotalSize(const wxSize
& clientSize
, int flags
) const;
260 virtual wxSize
GetFrameMinSize(int flags
) const;
262 virtual wxSize
GetFrameIconSize() const;
264 virtual int HitTestFrame(const wxRect
& rect
,
266 int flags
= 0) const;
269 // override base class border drawing routines: we always draw just a
270 // single simple border
271 void DrawSimpleBorder(wxDC
& dc
, wxRect
*rect
)
272 { DrawRect(dc
, rect
, m_penFg
); }
274 virtual void DrawRaisedBorder(wxDC
& dc
, wxRect
*rect
)
275 { DrawSimpleBorder(dc
, rect
); }
276 virtual void DrawSunkenBorder(wxDC
& dc
, wxRect
*rect
)
277 { DrawSimpleBorder(dc
, rect
); }
278 virtual void DrawAntiSunkenBorder(wxDC
& dc
, wxRect
*rect
)
279 { DrawSimpleBorder(dc
, rect
); }
280 virtual void DrawFrameBorder(wxDC
& dc
, wxRect
*rect
)
281 { DrawSimpleBorder(dc
, rect
); }
283 // all our XPMs are of this size
284 static wxSize
GetStdBmpSize() { return wxSize(8, 8); }
286 wxBitmap
GetIndicator(IndicatorType indType
, int flags
);
287 virtual wxBitmap
GetCheckBitmap(int flags
)
288 { return GetIndicator(IndicatorType_Check
, flags
); }
289 virtual wxBitmap
GetRadioBitmap(int flags
)
290 { return GetIndicator(IndicatorType_Radio
, flags
); }
293 // the bitmaps returned by GetIndicator()
294 wxBitmap m_bmpIndicators
[IndicatorType_MaxCtrl
]
295 [IndicatorState_MaxCtrl
]
296 [IndicatorStatus_Max
];
298 static const char **ms_xpmIndicators
[IndicatorType_MaxCtrl
]
299 [IndicatorState_MaxCtrl
]
300 [IndicatorStatus_Max
];
302 // the arrow bitmaps used by DrawArrow()
303 wxBitmap m_bmpArrows
[Arrow_Max
];
305 static const char **ms_xpmArrows
[Arrow_Max
];
307 // pen used for foreground drawing
311 // ----------------------------------------------------------------------------
313 // ----------------------------------------------------------------------------
315 static const char *xpmUnchecked
[] = {
316 /* columns rows colors chars-per-pixel */
331 static const char *xpmChecked
[] = {
332 /* columns rows colors chars-per-pixel */
347 static const char *xpmUndeterminate
[] = {
348 /* columns rows colors chars-per-pixel */
363 static const char *xpmRadioUnchecked
[] = {
364 /* columns rows colors chars-per-pixel */
379 static const char *xpmRadioChecked
[] = {
380 /* columns rows colors chars-per-pixel */
395 const char **wxMonoRenderer::ms_xpmIndicators
[IndicatorType_MaxCtrl
]
396 [IndicatorState_MaxCtrl
]
397 [IndicatorStatus_Max
] =
402 { xpmChecked
, xpmUnchecked
, xpmUndeterminate
},
405 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
408 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
414 { xpmRadioChecked
, xpmRadioUnchecked
, xpmUndeterminate
},
417 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
420 { xpmUndeterminate
, xpmUndeterminate
, xpmUndeterminate
},
424 static const char *xpmLeftArrow
[] = {
425 /* columns rows colors chars-per-pixel */
440 static const char *xpmRightArrow
[] = {
441 /* columns rows colors chars-per-pixel */
456 static const char *xpmUpArrow
[] = {
457 /* columns rows colors chars-per-pixel */
472 static const char *xpmDownArrow
[] = {
473 /* columns rows colors chars-per-pixel */
488 const char **wxMonoRenderer::ms_xpmArrows
[Arrow_Max
] =
490 xpmLeftArrow
, xpmRightArrow
, xpmUpArrow
, xpmDownArrow
,
493 // ----------------------------------------------------------------------------
494 // wxMonoColourScheme: uses just white and black
495 // ----------------------------------------------------------------------------
497 class wxMonoColourScheme
: public wxColourScheme
500 // we use only 2 colours, white and black, but we avoid referring to them
501 // like this, instead use the functions below
502 wxColour
GetFg() const { return wxMONO_FG_COL
; }
503 wxColour
GetBg() const { return wxMONO_BG_COL
; }
505 // implement base class pure virtuals
506 virtual wxColour
Get(StdColour col
) const;
507 virtual wxColour
GetBackground(wxWindow
*win
) const;
510 // ----------------------------------------------------------------------------
512 // ----------------------------------------------------------------------------
514 class wxMonoArtProvider
: public wxArtProvider
517 virtual wxBitmap
CreateBitmap(const wxArtID
& id
,
518 const wxArtClient
& client
,
522 // ----------------------------------------------------------------------------
524 // ----------------------------------------------------------------------------
526 class wxMonoTheme
: public wxTheme
530 virtual ~wxMonoTheme();
532 virtual wxRenderer
*GetRenderer();
533 virtual wxArtProvider
*GetArtProvider();
534 virtual wxInputHandler
*GetInputHandler(const wxString
& control
,
535 wxInputConsumer
*consumer
);
536 virtual wxColourScheme
*GetColourScheme();
539 wxMonoRenderer
*m_renderer
;
540 wxMonoArtProvider
*m_artProvider
;
541 wxMonoColourScheme
*m_scheme
;
543 WX_DECLARE_THEME(mono
)
546 // ============================================================================
548 // ============================================================================
550 WX_IMPLEMENT_THEME(wxMonoTheme
, mono
, wxTRANSLATE("Simple monochrome theme"));
552 // ----------------------------------------------------------------------------
554 // ----------------------------------------------------------------------------
556 wxMonoTheme::wxMonoTheme()
560 m_artProvider
= NULL
;
563 wxMonoTheme::~wxMonoTheme()
567 wxArtProvider::RemoveProvider(m_artProvider
);
570 wxRenderer
*wxMonoTheme::GetRenderer()
574 m_renderer
= new wxMonoRenderer(GetColourScheme());
580 wxArtProvider
*wxMonoTheme::GetArtProvider()
582 if ( !m_artProvider
)
584 m_artProvider
= new wxMonoArtProvider
;
587 return m_artProvider
;
590 wxColourScheme
*wxMonoTheme::GetColourScheme()
594 m_scheme
= new wxMonoColourScheme
;
600 wxInputHandler
*wxMonoTheme::GetInputHandler(const wxString
& WXUNUSED(control
),
601 wxInputConsumer
*consumer
)
603 // no special input handlers so far
604 return consumer
->DoGetStdInputHandler(NULL
);
607 // ============================================================================
608 // wxMonoColourScheme
609 // ============================================================================
611 wxColour
wxMonoColourScheme::GetBackground(wxWindow
*win
) const
614 if ( win
->UseBgCol() )
616 // use the user specified colour
617 col
= win
->GetBackgroundColour();
620 // doesn't depend on the state
629 wxColour
wxMonoColourScheme::Get(wxMonoColourScheme::StdColour col
) const
635 case CONTROL_PRESSED
:
636 case CONTROL_CURRENT
:
638 case SCROLLBAR_PRESSED
:
642 case TITLEBAR_ACTIVE
:
648 wxFAIL_MSG(_T("invalid standard colour"));
652 case SHADOW_HIGHLIGHT
:
656 case CONTROL_TEXT_DISABLED
:
657 case CONTROL_TEXT_DISABLED_SHADOW
:
660 case TITLEBAR_ACTIVE_TEXT
:
666 // ============================================================================
668 // ============================================================================
670 // ----------------------------------------------------------------------------
672 // ----------------------------------------------------------------------------
674 wxMonoRenderer::wxMonoRenderer(const wxColourScheme
*scheme
)
675 : wxStdRenderer(scheme
)
677 m_penFg
= wxPen(wxMONO_FG_COL
);
680 // ----------------------------------------------------------------------------
682 // ----------------------------------------------------------------------------
684 void wxMonoRenderer::DrawBorder(wxDC
& dc
,
686 const wxRect
& rectTotal
,
690 wxRect rect
= rectTotal
;
694 case wxBORDER_DOUBLE
:
695 DrawSimpleBorder(dc
, &rect
);
698 case wxBORDER_SUNKEN
:
699 case wxBORDER_STATIC
:
700 case wxBORDER_RAISED
:
701 case wxBORDER_SIMPLE
:
702 DrawSimpleBorder(dc
, &rect
);
706 wxFAIL_MSG(_T("unknown border type"));
709 case wxBORDER_DEFAULT
:
718 void wxMonoRenderer::DrawButtonBorder(wxDC
& dc
,
723 DrawBorder(dc
, wxBORDER_SIMPLE
, rect
, flags
, rectIn
);
726 // ----------------------------------------------------------------------------
728 // ----------------------------------------------------------------------------
731 wxMonoRenderer::DrawHorizontalLine(wxDC
& dc
, wxCoord y
, wxCoord x1
, wxCoord x2
)
734 dc
.DrawLine(x1
, y
, x2
+ 1, y
);
738 wxMonoRenderer::DrawVerticalLine(wxDC
& dc
, wxCoord x
, wxCoord y1
, wxCoord y2
)
741 dc
.DrawLine(x
, y1
, x
, y2
+ 1);
744 // ----------------------------------------------------------------------------
746 // ----------------------------------------------------------------------------
748 void wxMonoRenderer::DrawButtonLabel(wxDC
& dc
,
749 const wxString
& label
,
750 const wxBitmap
& image
,
757 dc
.SetTextForeground(m_penFg
.GetColour());
758 dc
.DrawLabel(label
, image
, rect
, alignment
, indexAccel
, rectBounds
);
760 if ( flags
& wxCONTROL_DISABLED
)
762 // this is ugly but I don't know how to show disabled button visually
763 // in monochrome theme otherwise, so cross it out
765 dc
.DrawLine(rect
.GetTopLeft(), rect
.GetBottomRight());
766 dc
.DrawLine(rect
.GetTopRight(), rect
.GetBottomLeft());
770 // ----------------------------------------------------------------------------
771 // check/radion buttons
772 // ----------------------------------------------------------------------------
774 wxBitmap
wxMonoRenderer::GetIndicator(IndicatorType indType
, int flags
)
776 IndicatorState indState
;
777 IndicatorStatus indStatus
;
778 GetIndicatorsFromFlags(flags
, indState
, indStatus
);
780 wxBitmap
& bmp
= m_bmpIndicators
[indType
][indState
][indStatus
];
783 const char **xpm
= ms_xpmIndicators
[indType
][indState
][indStatus
];
786 // create and cache it
794 // ----------------------------------------------------------------------------
796 // ----------------------------------------------------------------------------
800 void wxMonoRenderer::DrawToolBarButton(wxDC
& dc
,
801 const wxString
& label
,
802 const wxBitmap
& bitmap
,
808 wxFAIL_MSG(_T("TODO"));
811 #endif // wxUSE_TOOLBAR
813 // ----------------------------------------------------------------------------
815 // ----------------------------------------------------------------------------
819 void wxMonoRenderer::DrawTab(wxDC
& dc
,
822 const wxString
& label
,
823 const wxBitmap
& bitmap
,
827 wxFAIL_MSG(_T("TODO"));
830 #endif // wxUSE_NOTEBOOK
832 // ----------------------------------------------------------------------------
834 // ----------------------------------------------------------------------------
838 void wxMonoRenderer::GetComboBitmaps(wxBitmap
*bmpNormal
,
840 wxBitmap
*bmpPressed
,
841 wxBitmap
*bmpDisabled
)
843 wxFAIL_MSG(_T("TODO"));
846 #endif // wxUSE_COMBOBOX
848 // ----------------------------------------------------------------------------
850 // ----------------------------------------------------------------------------
852 void wxMonoRenderer::DrawArrow(wxDC
& dc
,
857 ArrowDirection arrowDir
= GetArrowDirection(dir
);
858 wxCHECK_RET( arrowDir
!= Arrow_Max
, _T("invalid arrow direction") );
860 wxBitmap
& bmp
= m_bmpArrows
[arrowDir
];
863 bmp
= wxBitmap(ms_xpmArrows
[arrowDir
]);
866 wxRect
rectArrow(0, 0, bmp
.GetWidth(), bmp
.GetHeight());
867 dc
.DrawBitmap(bmp
, rectArrow
.CentreIn(rect
).GetPosition(), true /* use mask */);
870 void wxMonoRenderer::DrawScrollbarThumb(wxDC
& dc
,
871 wxOrientation
WXUNUSED(orient
),
875 DrawSolidRect(dc
, wxMONO_FG_COL
, rect
);
878 void wxMonoRenderer::DrawScrollbarShaft(wxDC
& dc
,
879 wxOrientation
WXUNUSED(orient
),
883 DrawSolidRect(dc
, wxMONO_BG_COL
, rect
);
886 // ----------------------------------------------------------------------------
888 // ----------------------------------------------------------------------------
890 void wxMonoRenderer::DrawFrameTitleBar(wxDC
& WXUNUSED(dc
),
891 const wxRect
& WXUNUSED(rect
),
892 const wxString
& WXUNUSED(title
),
893 const wxIcon
& WXUNUSED(icon
),
895 int WXUNUSED(specialButton
),
896 int WXUNUSED(specialButtonFlag
))
900 void wxMonoRenderer::DrawFrameBorder(wxDC
& WXUNUSED(dc
),
901 const wxRect
& WXUNUSED(rect
),
906 void wxMonoRenderer::DrawFrameBackground(wxDC
& WXUNUSED(dc
),
907 const wxRect
& WXUNUSED(rect
),
912 void wxMonoRenderer::DrawFrameTitle(wxDC
& WXUNUSED(dc
),
913 const wxRect
& WXUNUSED(rect
),
914 const wxString
& WXUNUSED(title
),
919 void wxMonoRenderer::DrawFrameIcon(wxDC
& WXUNUSED(dc
),
920 const wxRect
& WXUNUSED(rect
),
921 const wxIcon
& WXUNUSED(icon
),
926 void wxMonoRenderer::DrawFrameButton(wxDC
& WXUNUSED(dc
),
929 int WXUNUSED(button
),
935 wxMonoRenderer::GetFrameClientArea(const wxRect
& rect
,
936 int WXUNUSED(flags
)) const
942 wxMonoRenderer::GetFrameTotalSize(const wxSize
& clientSize
,
943 int WXUNUSED(flags
)) const
948 wxSize
wxMonoRenderer::GetFrameMinSize(int WXUNUSED(flags
)) const
953 wxSize
wxMonoRenderer::GetFrameIconSize() const
955 return wxSize(wxDefaultCoord
, wxDefaultCoord
);
959 wxMonoRenderer::HitTestFrame(const wxRect
& WXUNUSED(rect
),
960 const wxPoint
& WXUNUSED(pt
),
961 int WXUNUSED(flags
)) const
963 return wxHT_TOPLEVEL_CLIENT_AREA
;
967 // ----------------------------------------------------------------------------
969 // ----------------------------------------------------------------------------
971 wxBitmap
wxMonoArtProvider::CreateBitmap(const wxArtID
& WXUNUSED(id
),
972 const wxArtClient
& WXUNUSED(client
),
973 const wxSize
& WXUNUSED(size
))