1///////////////////////////////////////////////////////////////////////////////
2// Name:        wx/univ/stdrend.h
3// Purpose:     wxStdRenderer class declaration
4// Author:      Vadim Zeitlin
5// Created:     2006-09-18
6// RCS-ID:      $Id: stdrend.h 42716 2006-10-30 12:33:25Z VS $
7// Copyright:   (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
8// Licence:     wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_UNIV_STDREND_H_
12#define _WX_UNIV_STDREND_H_
13
14#include "wx/univ/renderer.h"
15#include "wx/pen.h"
16
17class WXDLLEXPORT wxColourScheme;
18
19// ----------------------------------------------------------------------------
20// wxStdRenderer: implements as much of wxRenderer API as possible generically
21// ----------------------------------------------------------------------------
22
23class wxStdRenderer : public wxRenderer
24{
25public:
26    // the renderer will use the given scheme, whose lifetime must be at least
27    // as long as of this object itself, to choose the colours for drawing
28    wxStdRenderer(const wxColourScheme *scheme);
29
30    virtual void DrawBackground(wxDC& dc,
31                                const wxColour& col,
32                                const wxRect& rect,
33                                int flags = 0,
34                                wxWindow *window = NULL);
35    virtual void DrawButtonSurface(wxDC& dc,
36                                   const wxColour& col,
37                                   const wxRect& rect,
38                                   int flags);
39
40
41    virtual void DrawFocusRect(wxDC& dc, const wxRect& rect, int flags = 0);
42    virtual void DrawLabel(wxDC& dc,
43                           const wxString& label,
44                           const wxRect& rect,
45                           int flags = 0,
46                           int alignment = wxALIGN_LEFT | wxALIGN_TOP,
47                           int indexAccel = -1,
48                           wxRect *rectBounds = NULL);
49    virtual void DrawButtonLabel(wxDC& dc,
50                                 const wxString& label,
51                                 const wxBitmap& image,
52                                 const wxRect& rect,
53                                 int flags = 0,
54                                 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
55                                 int indexAccel = -1,
56                                 wxRect *rectBounds = NULL);
57
58
59    virtual void DrawBorder(wxDC& dc,
60                            wxBorder border,
61                            const wxRect& rect,
62                            int flags = 0,
63                            wxRect *rectIn = NULL);
64    virtual void DrawTextBorder(wxDC& dc,
65                                wxBorder border,
66                                const wxRect& rect,
67                                int flags = 0,
68                                wxRect *rectIn = NULL);
69
70    virtual void DrawHorizontalLine(wxDC& dc,
71                                    wxCoord y, wxCoord x1, wxCoord x2);
72    virtual void DrawVerticalLine(wxDC& dc,
73                                  wxCoord x, wxCoord y1, wxCoord y2);
74    virtual void DrawFrame(wxDC& dc,
75                           const wxString& label,
76                           const wxRect& rect,
77                           int flags = 0,
78                           int alignment = wxALIGN_LEFT,
79                           int indexAccel = -1);
80
81
82    virtual void DrawItem(wxDC& dc,
83                          const wxString& label,
84                          const wxRect& rect,
85                          int flags = 0);
86    virtual void DrawCheckItem(wxDC& dc,
87                               const wxString& label,
88                               const wxBitmap& bitmap,
89                               const wxRect& rect,
90                               int flags = 0);
91
92    virtual void DrawCheckButton(wxDC& dc,
93                                 const wxString& label,
94                                 const wxBitmap& bitmap,
95                                 const wxRect& rect,
96                                 int flags = 0,
97                                 wxAlignment align = wxALIGN_LEFT,
98                                 int indexAccel = -1);
99    virtual void DrawRadioButton(wxDC& dc,
100                                 const wxString& label,
101                                 const wxBitmap& bitmap,
102                                 const wxRect& rect,
103                                 int flags = 0,
104                                 wxAlignment align = wxALIGN_LEFT,
105                                 int indexAccel = -1);
106
107    virtual void DrawScrollbarArrow(wxDC& dc,
108                                    wxDirection dir,
109                                    const wxRect& rect,
110                                    int flags = 0);
111    virtual void DrawScrollCorner(wxDC& dc,
112                                  const wxRect& rect);
113
114#if wxUSE_TEXTCTRL
115    virtual void DrawTextLine(wxDC& dc,
116                              const wxString& text,
117                              const wxRect& rect,
118                              int selStart = -1,
119                              int selEnd = -1,
120                              int flags = 0);
121
122    virtual void DrawLineWrapMark(wxDC& dc, const wxRect& rect);
123
124    virtual wxRect GetTextTotalArea(const wxTextCtrl *text,
125                                    const wxRect& rect) const;
126    virtual wxRect GetTextClientArea(const wxTextCtrl *text,
127                                     const wxRect& rect,
128                                     wxCoord *extraSpaceBeyond) const;
129#endif // wxUSE_TEXTCTRL
130
131    virtual wxRect GetBorderDimensions(wxBorder border) const;
132
133    virtual bool AreScrollbarsInsideBorder() const;
134
135    virtual void AdjustSize(wxSize *size, const wxWindow *window);
136
137    virtual wxCoord GetListboxItemHeight(wxCoord fontHeight);
138
139#if wxUSE_STATUSBAR
140    virtual void DrawStatusField(wxDC& dc,
141                                 const wxRect& rect,
142                                 const wxString& label,
143                                 int flags = 0, int style = 0);
144
145    virtual wxSize GetStatusBarBorders() const;
146
147    virtual wxCoord GetStatusBarBorderBetweenFields() const;
148
149    virtual wxSize GetStatusBarFieldMargins() const;
150#endif // wxUSE_STATUSBAR
151
152    virtual wxCoord GetCheckItemMargin() const { return 0; }
153
154
155    virtual void DrawFrameTitleBar(wxDC& dc,
156                                   const wxRect& rect,
157                                   const wxString& title,
158                                   const wxIcon& icon,
159                                   int flags,
160                                   int specialButton = 0,
161                                   int specialButtonFlag = 0);
162    virtual void DrawFrameBorder(wxDC& dc,
163                                 const wxRect& rect,
164                                 int flags);
165    virtual void DrawFrameBackground(wxDC& dc,
166                                     const wxRect& rect,
167                                     int flags);
168    virtual void DrawFrameTitle(wxDC& dc,
169                                const wxRect& rect,
170                                const wxString& title,
171                                int flags);
172    virtual void DrawFrameIcon(wxDC& dc,
173                               const wxRect& rect,
174                               const wxIcon& icon,
175                               int flags);
176    virtual void DrawFrameButton(wxDC& dc,
177                                 wxCoord x, wxCoord y,
178                                 int button,
179                                 int flags = 0);
180
181    virtual wxRect GetFrameClientArea(const wxRect& rect, int flags) const;
182
183    virtual wxSize GetFrameTotalSize(const wxSize& clientSize, int flags) const;
184
185    virtual wxSize GetFrameMinSize(int flags) const;
186
187    virtual wxSize GetFrameIconSize() const;
188
189    virtual int HitTestFrame(const wxRect& rect,
190                             const wxPoint& pt,
191                             int flags = 0) const;
192protected:
193    // various constants
194    enum ArrowDirection
195    {
196        Arrow_Left,
197        Arrow_Right,
198        Arrow_Up,
199        Arrow_Down,
200        Arrow_Max
201    };
202
203    enum ArrowStyle
204    {
205        Arrow_Normal,
206        Arrow_Disabled,
207        Arrow_Pressed,
208        Arrow_Inverted,
209        Arrow_InvertedDisabled,
210        Arrow_StateMax
211    };
212
213    enum FrameButtonType
214    {
215        FrameButton_Close,
216        FrameButton_Minimize,
217        FrameButton_Maximize,
218        FrameButton_Restore,
219        FrameButton_Help,
220        FrameButton_Max
221    };
222
223    enum IndicatorType
224    {
225        IndicatorType_Check,
226        IndicatorType_Radio,
227        IndicatorType_MaxCtrl,
228        IndicatorType_Menu = IndicatorType_MaxCtrl,
229        IndicatorType_Max
230    };
231
232    enum IndicatorState
233    {
234        IndicatorState_Normal,
235        IndicatorState_Pressed, // this one is for check/radioboxes
236        IndicatorState_Disabled,
237        IndicatorState_MaxCtrl,
238
239        // the rest of the states are valid for menu items only
240        IndicatorState_Selected = IndicatorState_Pressed,
241        IndicatorState_SelectedDisabled = IndicatorState_MaxCtrl,
242        IndicatorState_MaxMenu
243    };
244
245    enum IndicatorStatus
246    {
247        IndicatorStatus_Checked,
248        IndicatorStatus_Unchecked,
249        IndicatorStatus_Undetermined,
250        IndicatorStatus_Max
251    };
252
253    // translate the appropriate bits in flags to the above enum elements
254    static void GetIndicatorsFromFlags(int flags,
255                                       IndicatorState& state,
256                                       IndicatorStatus& status);
257
258    // translate wxDirection to ArrowDirection
259    static ArrowDirection GetArrowDirection(wxDirection dir);
260
261
262    // fill the rectangle with a brush of given colour (must be valid)
263    void DrawSolidRect(wxDC& dc, const wxColour& col, const wxRect& rect);
264
265
266    // all the functions in this section adjust the rect parameter to
267    // correspond to the interiour of the drawn area
268
269        // draw complete rectangle
270    void DrawRect(wxDC& dc, wxRect *rect, const wxPen& pen);
271
272        // draw the rectange using the first pen for the left and top sides
273        // and the second one for the bottom and right ones
274    void DrawShadedRect(wxDC& dc, wxRect *rect,
275                        const wxPen& pen1, const wxPen& pen2);
276
277        // border drawing routines, may be overridden in the derived class
278    virtual void DrawRaisedBorder(wxDC& dc, wxRect *rect);
279    virtual void DrawSunkenBorder(wxDC& dc, wxRect *rect);
280    virtual void DrawAntiSunkenBorder(wxDC& dc, wxRect *rect);
281    virtual void DrawBoxBorder(wxDC& dc, wxRect *rect);
282    virtual void DrawStaticBorder(wxDC& dc, wxRect *rect);
283    virtual void DrawExtraBorder(wxDC& dc, wxRect *rect);
284
285
286    // draw the frame with non-empty label inside the given rectText
287    virtual void DrawFrameWithLabel(wxDC& dc,
288                                    const wxString& label,
289                                    const wxRect& rectFrame,
290                                    const wxRect& rectText,
291                                    int flags,
292                                    int alignment,
293                                    int indexAccel);
294
295    // draw the (static box) frame without the part corresponding to rectLabel
296    void DrawFrameWithoutLabel(wxDC& dc,
297                               const wxRect& rectFrame,
298                               const wxRect& rectLabel);
299
300
301    // draw the bitmap for a check item (which is by default the same as check
302    // box one but may be different)
303    virtual void DrawCheckItemBitmap(wxDC& dc,
304                                     const wxBitmap& bitmap,
305                                     const wxRect& rect,
306                                     int flags);
307
308    // common routine for drawing check and radio buttons
309    void DrawCheckOrRadioButton(wxDC& dc,
310                                const wxString& label,
311                                const wxBitmap& bitmap,
312                                const wxRect& rect,
313                                int flags,
314                                wxAlignment align,
315                                int indexAccel);
316
317    // return the check/radio bitmap for the given flags
318    virtual wxBitmap GetRadioBitmap(int flags) = 0;
319    virtual wxBitmap GetCheckBitmap(int flags) = 0;
320
321    // return the frame icon bitmap
322    virtual wxBitmap GetFrameButtonBitmap(FrameButtonType type) = 0;
323
324    // get the width of either normal or resizeable frame border depending on
325    // whether flags contains wxTOPLEVEL_RESIZEABLE bit
326    //
327    // notice that these methods only make sense with standard border drawing
328    // code which uses the borders of the same width on all sides, this is why
329    // they are only present here and not in wxRenderer itself
330    virtual int GetFrameBorderWidth(int flags) const;
331
332#if wxUSE_TEXTCTRL
333    // return the width of the border around the text area in the text control
334    virtual int GetTextBorderWidth(const wxTextCtrl *text) const;
335#endif // wxUSE_TEXTCTRL
336
337    // GDI objects we often use
338    wxPen m_penBlack,
339          m_penDarkGrey,
340          m_penLightGrey,
341          m_penHighlight;
342
343    wxFont m_titlebarFont;
344
345    // the colours we use, they never change currently so we don't have to ever
346    // update m_penXXX objects above
347    const wxColourScheme * const m_scheme;
348
349    DECLARE_NO_COPY_CLASS(wxStdRenderer)
350};
351
352#endif // _WX_UNIV_STDREND_H_
353