File: renderer.h

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (589 lines) | stat: -rw-r--r-- 21,803 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
/////////////////////////////////////////////////////////////////////////////
// Name:        renderer.h
// Purpose:     interface of wxRendererNative
// Author:      wxWidgets team
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

/**
    @anchor wxCONTROL_FLAGS

    The following rendering flags are defined for wxRendererNative:
*/
enum
{
    /** Control is disabled. */
    wxCONTROL_DISABLED   = 0x00000001,

    /** Currently has keyboard focus. */
    wxCONTROL_FOCUSED    = 0x00000002,

    /** (Button) is pressed. */
    wxCONTROL_PRESSED    = 0x00000004,

    /** Control-specific bit. */
    wxCONTROL_SPECIAL    = 0x00000008,

    /** Only for the buttons. */
    wxCONTROL_ISDEFAULT  = wxCONTROL_SPECIAL,

    /** Only for the menu items. */
    wxCONTROL_ISSUBMENU  = wxCONTROL_SPECIAL,

    /** Only for the tree items. */
    wxCONTROL_EXPANDED   = wxCONTROL_SPECIAL,

    /** Only for the status bar panes. */
    wxCONTROL_SIZEGRIP   = wxCONTROL_SPECIAL,

    /** Checkboxes only: flat border. */
    wxCONTROL_FLAT       = wxCONTROL_SPECIAL,

    /** Mouse is currently over the control. */
    wxCONTROL_CURRENT    = 0x00000010,

    /** Selected item in e.g.\ listbox. */
    wxCONTROL_SELECTED   = 0x00000020,

    /** (Check/radio button) is checked. */
    wxCONTROL_CHECKED    = 0x00000040,

    /** (Menu) item can be checked. */
    wxCONTROL_CHECKABLE  = 0x00000080,

    /** (Check) undetermined state. */
    wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE
};

/**
    Title bar buttons supported by wxRendererNative::DrawTitleBarBitmap().
 */
enum wxTitleBarButton
{
    wxTITLEBAR_BUTTON_CLOSE    = 0x01000000,
    wxTITLEBAR_BUTTON_MAXIMIZE = 0x02000000,
    wxTITLEBAR_BUTTON_ICONIZE  = 0x04000000,
    wxTITLEBAR_BUTTON_RESTORE  = 0x08000000,
    wxTITLEBAR_BUTTON_HELP     = 0x10000000
};

/**
    @struct wxSplitterRenderParams

    This is just a simple @c struct used as a return value of
    wxRendererNative::GetSplitterParams().

    It doesn't have any methods and all of its fields are constant, so they can
    only be examined but not modified.

    @library{wxcore}
    @category{gdi}
*/
struct wxSplitterRenderParams
{
    /**
        The only way to initialize this struct is by using this ctor.
    */
    wxSplitterRenderParams(wxCoord widthSash_, wxCoord border_, bool isSens_);

    /**
        The width of the border drawn by the splitter inside it, may be 0.
    */
    const wxCoord border;

    /**
        @true if the sash changes appearance when the mouse passes over it, @false
        otherwise.
    */
    const bool isHotSensitive;

    /**
        The width of the splitter sash.
    */
    const wxCoord widthSash;
};

/**
    @struct wxHeaderButtonParams

    This @c struct can optionally be used with
    wxRendererNative::DrawHeaderButton() to specify custom values used to draw
    the text or bitmap label.

    @library{wxcore}
    @category{gdi}
*/
struct wxHeaderButtonParams
{
    wxHeaderButtonParams();

    wxColour    m_arrowColour;
    wxColour    m_selectionColour;
    wxString    m_labelText;
    wxFont      m_labelFont;
    wxColour    m_labelColour;
    wxBitmap    m_labelBitmap;
    int         m_labelAlignment;
};

/**
    Used to specify the type of sort arrow used with
    wxRendererNative::DrawHeaderButton().
*/
enum wxHeaderSortIconType
{
    wxHDR_SORT_ICON_NONE,    ///< Don't draw a sort arrow.
    wxHDR_SORT_ICON_UP,      ///< Draw a sort arrow icon pointing up.
    wxHDR_SORT_ICON_DOWN     ///< Draw a sort arrow icon pointing down.
};



/**
    @class wxDelegateRendererNative

    wxDelegateRendererNative allows reuse of renderers code by forwarding all the
    wxRendererNative methods to the given object and
    thus allowing you to only modify some of its methods -- without having to
    reimplement all of them.

    Note that the "normal", inheritance-based approach, doesn't work with the
    renderers as it is impossible to derive from a class unknown at compile-time
    and the renderer is only chosen at run-time. So suppose that you want to only
    add something to the drawing of the tree control buttons but leave all the
    other methods unchanged -- the only way to do it, considering that the renderer
    class which you want to customize might not even be written yet when you write
    your code (it could be written later and loaded from a DLL during run-time), is
    by using this class.

    Except for the constructor, it has exactly the same methods as
    wxRendererNative and their implementation is
    trivial: they are simply forwarded to the real renderer. Note that the "real"
    renderer may, in turn, be a wxDelegateRendererNative as well and that there may
    be arbitrarily many levels like this -- but at the end of the chain there must
    be a real renderer which does the drawing.

    @library{wxcore}
    @category{gdi}

    @see wxRendererNative
*/
class wxDelegateRendererNative : public wxRendererNative
{
public:
    /**
        The default constructor does the same thing as the other one except that it
        uses the @ref wxRendererNative::GetGeneric() "generic renderer" instead of the
        user-specified @a rendererNative.

        In any case, this sets up the delegate renderer object to follow all calls to
        the specified real renderer.
    */
    wxDelegateRendererNative();
    /**
        This constructor uses the user-specified @a rendererNative to set up the delegate
        renderer object to follow all calls to the specified real renderer.

        @note
        This object does not take ownership of (i.e. won't delete) @a rendererNative.
    */
    wxDelegateRendererNative(wxRendererNative& rendererNative);

    // The rest of these functions inherit the documentation from wxRendererNative

    virtual int DrawHeaderButton(wxWindow *win, wxDC& dc,
                                 const wxRect& rect, int flags = 0,
                                 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                 wxHeaderButtonParams* params = NULL);

    virtual int DrawHeaderButtonContents(wxWindow *win, wxDC& dc,
                                         const wxRect& rect, int flags = 0,
                                         wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
                                         wxHeaderButtonParams* params = NULL);

    virtual int GetHeaderButtonHeight(wxWindow *win);

    virtual int GetHeaderButtonMargin(wxWindow *win);

    virtual void DrawTreeItemButton(wxWindow *win, wxDC& dc,
                                    const wxRect& rect, int flags = 0);

    virtual void DrawSplitterBorder(wxWindow *win, wxDC& dc,
                                    const wxRect& rect, int flags = 0);

    virtual void DrawSplitterSash(wxWindow *win, wxDC& dc,
                                  const wxSize& size, wxCoord position,
                                  wxOrientation orient, int flags = 0);

    virtual void DrawComboBoxDropButton(wxWindow *win, wxDC& dc,
                                        const wxRect& rect, int flags = 0);

    virtual void DrawDropArrow(wxWindow *win, wxDC& dc,
                               const wxRect& rect, int flags = 0);

    virtual void DrawCheckBox(wxWindow *win, wxDC& dc,
                              const wxRect& rect, int flags = 0 );

    virtual wxSize GetCheckBoxSize(wxWindow *win);

    virtual void DrawPushButton(wxWindow *win, wxDC& dc,
                                const wxRect& rect, int flags = 0 );

    virtual void DrawItemSelectionRect(wxWindow *win, wxDC& dc,
                                       const wxRect& rect, int flags = 0 );

    virtual void DrawFocusRect(wxWindow* win, wxDC& dc,
                               const wxRect& rect, int flags = 0);

    virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);

    virtual wxRendererVersion GetVersion() const;
};



/**
    @class wxRendererNative

    First, a brief introduction to wxRendererNative and why it is needed.

    Usually wxWidgets uses the underlying low level GUI system to draw all the
    controls - this is what we mean when we say that it is a "native" framework.
    However not all controls exist under all (or even any) platforms and in this
    case wxWidgets provides a default, generic, implementation of them written in
    wxWidgets itself.

    These controls don't have the native appearance if only the standard
    line drawing and other graphics primitives are used, because the native
    appearance is different under different platforms while the lines are always
    drawn in the same way.

    This is why we have renderers: wxRendererNative is a class which virtualizes the
    drawing, i.e. it abstracts the drawing operations and allows you to draw say, a
    button, without caring about exactly how this is done. Of course, as we
    can draw the button differently in different renderers, this also allows us to
    emulate the native look and feel.

    So the renderers work by exposing a large set of high-level drawing functions
    which are used by the generic controls. There is always a default global
    renderer but it may be changed or extended by the user, see
    @ref page_samples_render.

    All drawing functions take some standard parameters:

    @li @a win - The window being drawn. It is normally not used and when
    it is it should only be used as a generic wxWindow
    (in order to get its low level handle, for example), but you should
    not assume that it is of some given type as the same renderer
    function may be reused for drawing different kinds of control.
    @li @a dc - The wxDC to draw on. Only this device
    context should be used for drawing. It is not necessary to restore
    pens and brushes for it on function exit but, on the other hand, you
    shouldn't assume that it is in any specific state on function entry:
    the rendering functions should always prepare it.
    @li @a rect - The bounding rectangle for the element to be drawn.
    @li @a flags - The optional flags (none by default) which can be a
    combination of the @ref wxCONTROL_FLAGS.

    Note that each drawing function restores the wxDC attributes if
    it changes them, so it is safe to assume that the same pen, brush and colours
    that were active before the call to this function are still in effect after it.

    @library{wxcore}
    @category{gdi}
*/
class wxRendererNative
{
public:
    /**
        Virtual destructor as for any base class.
    */
    virtual ~wxRendererNative();

    /**
        Draw a check box.

        @a flags may have the @c wxCONTROL_CHECKED, @c wxCONTROL_CURRENT or
        @c wxCONTROL_UNDETERMINED bit set, see @ref wxCONTROL_FLAGS.
    */
    virtual void DrawCheckBox(wxWindow* win, wxDC& dc, const wxRect& rect,
                              int flags = 0) = 0;

    /**
        Draw a button like the one used by wxComboBox to show a
        drop down window. The usual appearance is a downwards pointing arrow.

        @a flags may have the @c wxCONTROL_PRESSED or @c wxCONTROL_CURRENT bit set,
        see @ref wxCONTROL_FLAGS.
    */
    virtual void DrawComboBoxDropButton(wxWindow* win, wxDC& dc,
                                        const wxRect& rect, int flags = 0) = 0;

    /**
        Draw a drop down arrow that is suitable for use outside a combo box. Arrow will
        have transparent background.

        @a rect is not entirely filled by the arrow. Instead, you should use bounding
        rectangle of a drop down button which arrow matches the size you need.

        @a flags may have the @c wxCONTROL_PRESSED or @c wxCONTROL_CURRENT bit set,
        see @ref wxCONTROL_FLAGS.
    */
    virtual void DrawDropArrow(wxWindow* win, wxDC& dc, const wxRect& rect,
                               int flags = 0) = 0;

    /**
        Draw a focus rectangle using the specified rectangle.
        wxListCtrl.

        The only supported flags is @c wxCONTROL_SELECTED for items which are selected.
        see @ref wxCONTROL_FLAGS.
    */
    virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect,
                               int flags = 0) = 0;

    /**
        Draw the header control button (used, for example, by wxListCtrl).

        Depending on platforms the @a flags parameter may support the @c wxCONTROL_SELECTED
        @c wxCONTROL_DISABLED and @c wxCONTROL_CURRENT bits, see @ref wxCONTROL_FLAGS.

        @return
        The optimal width to contain the unabbreviated label text or
        bitmap, the sort arrow if present, and internal margins.
    */
    virtual int DrawHeaderButton(wxWindow* win, wxDC& dc, const wxRect& rect,
                                 int flags = 0,
                                 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, wxHeaderButtonParams* params = NULL) = 0;

    /**
        Draw the contents of a header control button (label, sort arrows,
        etc.). This function is normally only called by DrawHeaderButton().

        Depending on platforms the @a flags parameter may support the @c wxCONTROL_SELECTED
        @c wxCONTROL_DISABLED and @c wxCONTROL_CURRENT bits, see @ref wxCONTROL_FLAGS.

        @return
        The optimal width to contain the unabbreviated label text or
        bitmap, the sort arrow if present, and internal margins.
    */
    virtual int DrawHeaderButtonContents(wxWindow* win, wxDC& dc,
                                         const wxRect& rect, int flags = 0,
                                         wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, wxHeaderButtonParams* params = NULL) = 0;

    /**
        Draw a selection rectangle underneath the text as used e.g. in a
        wxListCtrl.

        The supported @a flags are @c wxCONTROL_SELECTED for items
        which are selected (e.g. often a blue rectangle) and @c wxCONTROL_CURRENT
        for the item that has the focus (often a dotted line around the item's text).
        @c wxCONTROL_FOCUSED may be used to indicate if the control has the focus
        (otherwise the selection rectangle is e.g. often grey and not blue).
        This may be ignored by the renderer or deduced by the code directly from
        the @a win.
    */
    virtual void DrawItemSelectionRect(wxWindow* win, wxDC& dc,
                                       const wxRect& rect, int flags = 0) = 0;

    /**
        Draw a blank push button that looks very similar to wxButton.

        @a flags may have the @c wxCONTROL_PRESSED, @c wxCONTROL_CURRENT or
        @c wxCONTROL_ISDEFAULT bit set, see @ref wxCONTROL_FLAGS.
    */
    virtual void DrawPushButton(wxWindow* win, wxDC& dc, const wxRect& rect,
                                int flags = 0) = 0;

    /**
        Draw the border for sash window: this border must be such that the sash
        drawn by DrawSplitterSash() blends into it well.
    */
    virtual void DrawSplitterBorder(wxWindow* win, wxDC& dc, const wxRect& rect,
                                    int flags = 0) = 0;

    /**
        Draw a sash. The @a orient parameter defines whether the sash should be
        vertical or horizontal and how the @a position should be interpreted.
    */
    virtual void DrawSplitterSash(wxWindow* win, wxDC& dc, const wxSize& size,
                                  wxCoord position, wxOrientation orient,
                                  int flags = 0) = 0;

    /**
        Draw the expanded/collapsed icon for a tree control item.

        To draw an expanded button the @a flags parameter must contain @c wxCONTROL_EXPANDED bit,
        see @ref wxCONTROL_FLAGS.
    */
    virtual void DrawTreeItemButton(wxWindow* win, wxDC& dc, const wxRect& rect,
                                    int flags = 0) = 0;

    /**
        Draw a native wxChoice
    */
    virtual void DrawChoice(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0) = 0;

    /**
        Draw a native wxComboBox
    */
    virtual void DrawComboBox(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0) = 0;

    /**
        Draw a native wxTextCtrl frame
    */
    virtual void DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0) = 0;

    /**
        Draw a native wxRadioButton bitmap.
    */
    virtual void DrawRadioBitmap(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0) = 0;

    /**
        Draw a title bar button in the given state.

        This function is currently only available under MSW and OS X (and only
        for wxTITLEBAR_BUTTON_CLOSE under the latter), its best replacement for
        the other platforms is to use wxArtProvider to retrieve the bitmaps for
        @c wxART_HELP and @c wxART_CLOSE (but not any other title bar buttons
        and not for any state but normal, i.e. not pressed and not current one).

        The presence of this function is indicated by @c
        wxHAS_DRAW_TITLE_BAR_BITMAP symbol being defined.

        Also notice that PNG handler must be enabled using wxImage::AddHandler()
        to use this function under OS X currently as the bitmaps are embedded
        in the library itself in PNG format.

        @since 2.9.1
     */
    virtual void DrawTitleBarBitmap(wxWindow *win,
                                    wxDC& dc,
                                    const wxRect& rect,
                                    wxTitleBarButton button,
                                    int flags = 0) = 0;

    /**
        Return the currently used renderer.
    */
    static wxRendererNative& Get();

    /**
        Return the default (native) implementation for this platform -- this is also
        the one used by default but this may be changed by calling
        Set() in which case the return value of this
        method may be different from the return value of Get().
    */
    static wxRendererNative& GetDefault();

    /**
        Return the generic implementation of the renderer. Under some platforms, this
        is the default renderer implementation, others have platform-specific default
        renderer which can be retrieved by calling GetDefault().
    */
    static wxRendererNative& GetGeneric();

    /**
        Returns the size of a check box.
        The @a win parameter is not used currently and can be @NULL.
    */
    virtual wxSize GetCheckBoxSize(wxWindow* win) = 0;

    /**
        Returns the height of a header button, either a fixed platform height if
        available, or a generic height based on the @a win window's font.
    */
    virtual int GetHeaderButtonHeight(wxWindow* win) = 0;

    /**
        Returns the horizontal margin on the left and right sides of header
        button's label.

        @since 2.9.2
     */
    virtual int GetHeaderButtonMargin(wxWindow *win) = 0;

    /**
        Get the splitter parameters, see wxSplitterRenderParams.
        The @a win parameter should be a wxSplitterWindow.
    */
    virtual wxSplitterRenderParams GetSplitterParams(const wxWindow* win) = 0;

    /**
        This function is used for version checking: Load()
        refuses to load any shared libraries implementing an older or incompatible
        version.

        @remarks
        The implementation of this method is always the same in all renderers (simply
        construct wxRendererVersion using the @c wxRendererVersion::Current_XXX values),
        but it has to be in the derived, not base, class, to detect mismatches between
        the renderers versions and so you have to implement it anew in all renderers.
    */
    virtual wxRendererVersion GetVersion() const = 0;

    /**
        Load the renderer from the specified DLL, the returned pointer must be
        deleted by caller if not @NULL when it is not used any more.

        The @a name should be just the base name of the renderer and not the full
        name of the DLL file which is constructed differently (using
        wxDynamicLibrary::CanonicalizePluginName())
        on different systems.
    */
    static wxRendererNative* Load(const wxString& name);

    /**
        Set the renderer to use, passing @NULL reverts to using the default
        renderer (the global renderer must always exist).

        Return the previous renderer used with Set() or @NULL if none.
    */
    static wxRendererNative* Set(wxRendererNative* renderer);
};



/**
    @struct wxRendererVersion

    This simple struct represents the wxRendererNative
    interface version and is only used as the return value of
    wxRendererNative::GetVersion().

    The version has two components: the version itself and the age. If the main
    program and the renderer have different versions they are never compatible with
    each other because the version is only changed when an existing virtual
    function is modified or removed. The age, on the other hand, is incremented
    each time a new virtual method is added and so, at least for the compilers
    using a common C++ object model, the calling program is compatible with any
    renderer which has the age greater or equal to its age. This verification is
    done by IsCompatible() method.

    @library{wxcore}
    @category{gdi}
*/
struct wxRendererVersion
{
    wxRendererVersion(int version_, int age_);
    
    /**
        Checks if the main program is compatible with the renderer having the version
        @e ver, returns @true if it is and @false otherwise.

        This method is used by wxRendererNative::Load() to determine whether a
        renderer can be used.
    */
    static bool IsCompatible(const wxRendererVersion& ver);

    /**
        The age component.
    */
    const int age;

    /**
        The version component.
    */
    const int version;
};