~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Externals/wxWidgets3/include/wx/scrolwin.h

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////////////////////
 
2
// Name:        wx/scrolwin.h
 
3
// Purpose:     wxScrolledWindow, wxScrolledControl and wxScrollHelper
 
4
// Author:      Vadim Zeitlin
 
5
// Modified by:
 
6
// Created:     30.08.00
 
7
// Copyright:   (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
 
8
// Licence:     wxWindows licence
 
9
/////////////////////////////////////////////////////////////////////////////
 
10
 
 
11
#ifndef _WX_SCROLWIN_H_BASE_
 
12
#define _WX_SCROLWIN_H_BASE_
 
13
 
 
14
#include "wx/panel.h"
 
15
 
 
16
class WXDLLIMPEXP_FWD_CORE wxScrollHelperEvtHandler;
 
17
class WXDLLIMPEXP_FWD_BASE wxTimer;
 
18
 
 
19
// default scrolled window style: scroll in both directions
 
20
#define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
 
21
 
 
22
// values for the second argument of wxScrollHelper::ShowScrollbars()
 
23
enum wxScrollbarVisibility
 
24
{
 
25
    wxSHOW_SB_NEVER = -1,   // never show the scrollbar at all
 
26
    wxSHOW_SB_DEFAULT,      // show scrollbar only if it is needed
 
27
    wxSHOW_SB_ALWAYS        // always show scrollbar, even if not needed
 
28
};
 
29
 
 
30
// ----------------------------------------------------------------------------
 
31
// The hierarchy of scrolling classes is a bit complicated because we want to
 
32
// put as much functionality as possible in a mix-in class not deriving from
 
33
// wxWindow so that other classes could derive from the same base class on all
 
34
// platforms irrespectively of whether they are native controls (and hence
 
35
// don't use our scrolling) or not.
 
36
//
 
37
// So we have
 
38
//
 
39
//                          wxAnyScrollHelperBase
 
40
//                                   |
 
41
//                                   |
 
42
//                                  \|/
 
43
//                           wxScrollHelperBase
 
44
//                                   |
 
45
//                                   |
 
46
//                                  \|/
 
47
//      wxWindow               wxScrollHelper
 
48
//       |  \                   /        /
 
49
//       |   \                 /        /
 
50
//       |    _|             |_        /
 
51
//       |     wxScrolledWindow       /
 
52
//       |                           /
 
53
//      \|/                         /
 
54
//   wxControl                     /
 
55
//         \                      /
 
56
//          \                    /
 
57
//           _|                |_
 
58
//            wxScrolledControl
 
59
//
 
60
// ----------------------------------------------------------------------------
 
61
 
 
62
// This class allows reusing some of wxScrollHelperBase functionality in
 
63
// wxVarScrollHelperBase in wx/vscroll.h without duplicating its code.
 
64
class WXDLLIMPEXP_CORE wxAnyScrollHelperBase
 
65
{
 
66
public:
 
67
    wxEXPLICIT wxAnyScrollHelperBase(wxWindow* win);
 
68
    virtual ~wxAnyScrollHelperBase() {}
 
69
 
 
70
    // Disable use of keyboard keys for scrolling. By default cursor movement
 
71
    // keys (including Home, End, Page Up and Down) are used to scroll the
 
72
    // window appropriately. If the derived class uses these keys for something
 
73
    // else, e.g. changing the currently selected item, this function can be
 
74
    // used to disable this behaviour as it's not only not necessary then but
 
75
    // can actually be actively harmful if another object forwards a keyboard
 
76
    // event corresponding to one of the above keys to us using
 
77
    // ProcessWindowEvent() because the event will always be processed which
 
78
    // can be undesirable.
 
79
    void DisableKeyboardScrolling() { m_kbdScrollingEnabled = false; }
 
80
 
 
81
    // Override this function to draw the graphic (or just process EVT_PAINT)
 
82
    virtual void OnDraw(wxDC& WXUNUSED(dc)) { }
 
83
 
 
84
    // change the DC origin according to the scroll position.
 
85
    virtual void DoPrepareDC(wxDC& dc) = 0;
 
86
 
 
87
    // Simple accessor for the window that is really being scrolled.
 
88
    wxWindow *GetTargetWindow() const { return m_targetWindow; }
 
89
 
 
90
 
 
91
    // The methods called from the window event handlers.
 
92
    void HandleOnChar(wxKeyEvent& event);
 
93
    void HandleOnPaint(wxPaintEvent& event);
 
94
 
 
95
protected:
 
96
    // the window that receives the scroll events and the window to actually
 
97
    // scroll, respectively
 
98
    wxWindow *m_win,
 
99
             *m_targetWindow;
 
100
 
 
101
    // whether cursor keys should scroll the window
 
102
    bool m_kbdScrollingEnabled;
 
103
};
 
104
 
 
105
// This is the class containing the guts of (uniform) scrolling logic.
 
106
class WXDLLIMPEXP_CORE wxScrollHelperBase : public wxAnyScrollHelperBase
 
107
{
 
108
public:
 
109
    // ctor must be given the associated window
 
110
    wxScrollHelperBase(wxWindow *winToScroll);
 
111
    virtual ~wxScrollHelperBase();
 
112
 
 
113
    // configure the scrolling
 
114
    virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
 
115
                               int noUnitsX, int noUnitsY,
 
116
                               int xPos = 0, int yPos = 0,
 
117
                               bool noRefresh = false );
 
118
 
 
119
    // scroll to the given (in logical coords) position
 
120
    //
 
121
    // notice that for backwards compatibility reasons Scroll() is virtual as
 
122
    // the existing code could override it but new code should override
 
123
    // DoScroll() instead
 
124
    virtual void Scroll(int x, int y) { DoScroll(x, y); }
 
125
    virtual void Scroll(const wxPoint& pt) { DoScroll(pt.x, pt.y); }
 
126
 
 
127
    // get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL)
 
128
    int GetScrollPageSize(int orient) const;
 
129
    void SetScrollPageSize(int orient, int pageSize);
 
130
 
 
131
    // get the number of lines the window can scroll,
 
132
    // returns 0 if no scrollbars are there.
 
133
    int GetScrollLines( int orient ) const;
 
134
 
 
135
    // Set the x, y scrolling increments.
 
136
    void SetScrollRate( int xstep, int ystep );
 
137
 
 
138
    // get the size of one logical unit in physical ones
 
139
    void GetScrollPixelsPerUnit(int *pixelsPerUnitX, int *pixelsPerUnitY) const;
 
140
 
 
141
    // Set scrollbar visibility: it is possible to show scrollbar only if it is
 
142
    // needed (i.e. if our virtual size is greater than the current size of the
 
143
    // associated window), always (as wxALWAYS_SHOW_SB style does) or never (in
 
144
    // which case you should provide some other way to scroll the window as the
 
145
    // user wouldn't be able to do it at all)
 
146
    void ShowScrollbars(wxScrollbarVisibility horz, wxScrollbarVisibility vert)
 
147
    {
 
148
        DoShowScrollbars(horz, vert);
 
149
    }
 
150
 
 
151
    // Test whether the specified scrollbar is shown.
 
152
    virtual bool IsScrollbarShown(int orient) const = 0;
 
153
 
 
154
    // Enable/disable Windows scrolling in either direction. If true, wxWidgets
 
155
    // scrolls the canvas and only a bit of the canvas is invalidated; no
 
156
    // Clear() is necessary. If false, the whole canvas is invalidated and a
 
157
    // Clear() is necessary. Disable for when the scroll increment is used to
 
158
    // actually scroll a non-constant distance
 
159
    //
 
160
    // Notice that calling this method with a false argument doesn't disable
 
161
    // scrolling the window in this direction, it just changes the mechanism by
 
162
    // which it is implemented to not use wxWindow::ScrollWindow().
 
163
    virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
 
164
 
 
165
    // Get the view start
 
166
    void GetViewStart(int *x, int *y) const { DoGetViewStart(x, y); }
 
167
 
 
168
    wxPoint GetViewStart() const
 
169
    {
 
170
        wxPoint pt;
 
171
        DoGetViewStart(&pt.x, &pt.y);
 
172
        return pt;
 
173
    }
 
174
 
 
175
    // Set the scale factor, used in PrepareDC
 
176
    void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; }
 
177
    double GetScaleX() const { return m_scaleX; }
 
178
    double GetScaleY() const { return m_scaleY; }
 
179
 
 
180
    // translate between scrolled and unscrolled coordinates
 
181
    void CalcScrolledPosition(int x, int y, int *xx, int *yy) const
 
182
        {  DoCalcScrolledPosition(x, y, xx, yy); }
 
183
    wxPoint CalcScrolledPosition(const wxPoint& pt) const
 
184
    {
 
185
        wxPoint p2;
 
186
        DoCalcScrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
 
187
        return p2;
 
188
    }
 
189
 
 
190
    void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
 
191
        {  DoCalcUnscrolledPosition(x, y, xx, yy); }
 
192
    wxPoint CalcUnscrolledPosition(const wxPoint& pt) const
 
193
    {
 
194
        wxPoint p2;
 
195
        DoCalcUnscrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
 
196
        return p2;
 
197
    }
 
198
 
 
199
    void DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const;
 
200
    void DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const;
 
201
 
 
202
    // Adjust the scrollbars
 
203
    virtual void AdjustScrollbars() = 0;
 
204
 
 
205
    // Calculate scroll increment
 
206
    int CalcScrollInc(wxScrollWinEvent& event);
 
207
 
 
208
    // Normally the wxScrolledWindow will scroll itself, but in some rare
 
209
    // occasions you might want it to scroll [part of] another window (e.g. a
 
210
    // child of it in order to scroll only a portion the area between the
 
211
    // scrollbars (spreadsheet: only cell area will move).
 
212
    void SetTargetWindow(wxWindow *target);
 
213
 
 
214
    void SetTargetRect(const wxRect& rect) { m_rectToScroll = rect; }
 
215
    wxRect GetTargetRect() const { return m_rectToScroll; }
 
216
 
 
217
    virtual void DoPrepareDC(wxDC& dc);
 
218
 
 
219
    // are we generating the autoscroll events?
 
220
    bool IsAutoScrolling() const { return m_timerAutoScroll != NULL; }
 
221
 
 
222
    // stop generating the scroll events when mouse is held outside the window
 
223
    void StopAutoScrolling();
 
224
 
 
225
    // this method can be overridden in a derived class to forbid sending the
 
226
    // auto scroll events - note that unlike StopAutoScrolling() it doesn't
 
227
    // stop the timer, so it will be called repeatedly and will typically
 
228
    // return different values depending on the current mouse position
 
229
    //
 
230
    // the base class version just returns true
 
231
    virtual bool SendAutoScrollEvents(wxScrollWinEvent& event) const;
 
232
 
 
233
    // the methods to be called from the window event handlers
 
234
    void HandleOnScroll(wxScrollWinEvent& event);
 
235
    void HandleOnSize(wxSizeEvent& event);
 
236
    void HandleOnMouseEnter(wxMouseEvent& event);
 
237
    void HandleOnMouseLeave(wxMouseEvent& event);
 
238
#if wxUSE_MOUSEWHEEL
 
239
    void HandleOnMouseWheel(wxMouseEvent& event);
 
240
#endif // wxUSE_MOUSEWHEEL
 
241
    void HandleOnChildFocus(wxChildFocusEvent& event);
 
242
 
 
243
#if WXWIN_COMPATIBILITY_2_8
 
244
    wxDEPRECATED(
 
245
        void OnScroll(wxScrollWinEvent& event) { HandleOnScroll(event); }
 
246
    )
 
247
#endif // WXWIN_COMPATIBILITY_2_8
 
248
 
 
249
protected:
 
250
    // get pointer to our scroll rect if we use it or NULL
 
251
    const wxRect *GetScrollRect() const
 
252
    {
 
253
        return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL;
 
254
    }
 
255
 
 
256
    // get the size of the target window
 
257
    wxSize GetTargetSize() const
 
258
    {
 
259
        return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize()
 
260
                                         : m_targetWindow->GetClientSize();
 
261
    }
 
262
 
 
263
    void GetTargetSize(int *w, int *h) const
 
264
    {
 
265
        wxSize size = GetTargetSize();
 
266
        if ( w )
 
267
            *w = size.x;
 
268
        if ( h )
 
269
            *h = size.y;
 
270
    }
 
271
 
 
272
    // implementation of public methods with the same name
 
273
    virtual void DoGetViewStart(int *x, int *y) const;
 
274
    virtual void DoScroll(int x, int y) = 0;
 
275
    virtual void DoShowScrollbars(wxScrollbarVisibility horz,
 
276
                                  wxScrollbarVisibility vert) = 0;
 
277
 
 
278
    // implementations of various wxWindow virtual methods which should be
 
279
    // forwarded to us (this can be done by WX_FORWARD_TO_SCROLL_HELPER())
 
280
    bool ScrollLayout();
 
281
    void ScrollDoSetVirtualSize(int x, int y);
 
282
    wxSize ScrollGetBestVirtualSize() const;
 
283
 
 
284
    // change just the target window (unlike SetWindow which changes m_win as
 
285
    // well)
 
286
    void DoSetTargetWindow(wxWindow *target);
 
287
 
 
288
    // delete the event handler we installed
 
289
    void DeleteEvtHandler();
 
290
 
 
291
    // this function should be overridden to return the size available for
 
292
    // m_targetWindow inside m_win of the given size
 
293
    //
 
294
    // the default implementation is only good for m_targetWindow == m_win
 
295
    // case, if we're scrolling a subwindow you must override this method
 
296
    virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size)
 
297
    {
 
298
        // returning just size from here is wrong but it was decided that it is
 
299
        // not wrong enough to break the existing code (which doesn't override
 
300
        // this recently added function at all) by adding this assert
 
301
        //
 
302
        // wxASSERT_MSG( m_targetWindow == m_win, "must be overridden" );
 
303
 
 
304
        return size;
 
305
    }
 
306
 
 
307
 
 
308
    double                m_scaleX;
 
309
    double                m_scaleY;
 
310
 
 
311
    wxRect                m_rectToScroll;
 
312
 
 
313
    wxTimer              *m_timerAutoScroll;
 
314
 
 
315
    // The number of pixels to scroll in horizontal and vertical directions
 
316
    // respectively.
 
317
    //
 
318
    // If 0, means that the scrolling in the given direction is disabled.
 
319
    int                   m_xScrollPixelsPerLine;
 
320
    int                   m_yScrollPixelsPerLine;
 
321
    int                   m_xScrollPosition;
 
322
    int                   m_yScrollPosition;
 
323
    int                   m_xScrollLines;
 
324
    int                   m_yScrollLines;
 
325
    int                   m_xScrollLinesPerPage;
 
326
    int                   m_yScrollLinesPerPage;
 
327
 
 
328
    bool                  m_xScrollingEnabled;
 
329
    bool                  m_yScrollingEnabled;
 
330
 
 
331
#if wxUSE_MOUSEWHEEL
 
332
    int m_wheelRotation;
 
333
#endif // wxUSE_MOUSEWHEEL
 
334
 
 
335
    wxScrollHelperEvtHandler *m_handler;
 
336
 
 
337
    wxDECLARE_NO_COPY_CLASS(wxScrollHelperBase);
 
338
};
 
339
 
 
340
// this macro can be used in a wxScrollHelper-derived class to forward wxWindow
 
341
// methods to corresponding wxScrollHelper methods
 
342
#define WX_FORWARD_TO_SCROLL_HELPER()                                         \
 
343
public:                                                                       \
 
344
    virtual void PrepareDC(wxDC& dc) { DoPrepareDC(dc); }                     \
 
345
    virtual bool Layout() { return ScrollLayout(); }                          \
 
346
    virtual bool CanScroll(int orient) const                                  \
 
347
        { return IsScrollbarShown(orient); }                                  \
 
348
    virtual void DoSetVirtualSize(int x, int y)                               \
 
349
        { ScrollDoSetVirtualSize(x, y); }                                     \
 
350
    virtual wxSize GetBestVirtualSize() const                                 \
 
351
        { return ScrollGetBestVirtualSize(); }
 
352
 
 
353
// include the declaration of the real wxScrollHelper
 
354
#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
 
355
    #include "wx/gtk/scrolwin.h"
 
356
#elif defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
 
357
    #include "wx/gtk1/scrolwin.h"
 
358
#else
 
359
    #define wxHAS_GENERIC_SCROLLWIN
 
360
    #include "wx/generic/scrolwin.h"
 
361
#endif
 
362
 
 
363
// ----------------------------------------------------------------------------
 
364
// wxScrolled<T>: a wxWindow which knows how to scroll
 
365
// ----------------------------------------------------------------------------
 
366
 
 
367
// helper class for wxScrolled<T> below
 
368
struct WXDLLIMPEXP_CORE wxScrolledT_Helper
 
369
{
 
370
    static wxSize FilterBestSize(const wxWindow *win,
 
371
                                 const wxScrollHelper *helper,
 
372
                                 const wxSize& origBest);
 
373
#ifdef __WXMSW__
 
374
    static WXLRESULT FilterMSWWindowProc(WXUINT nMsg, WXLRESULT origResult);
 
375
#endif
 
376
};
 
377
 
 
378
// Scrollable window base on window type T. This used to be wxScrolledWindow,
 
379
// but wxScrolledWindow includes wxControlContainer functionality and that's
 
380
// not always desirable.
 
381
template<class T>
 
382
class wxScrolled : public T,
 
383
                   public wxScrollHelper,
 
384
                   private wxScrolledT_Helper
 
385
{
 
386
public:
 
387
    wxScrolled() : wxScrollHelper(this) { }
 
388
    wxScrolled(wxWindow *parent,
 
389
               wxWindowID winid = wxID_ANY,
 
390
               const wxPoint& pos = wxDefaultPosition,
 
391
               const wxSize& size = wxDefaultSize,
 
392
               long style = wxScrolledWindowStyle,
 
393
               const wxString& name = wxPanelNameStr)
 
394
        : wxScrollHelper(this)
 
395
    {
 
396
        Create(parent, winid, pos, size, style, name);
 
397
    }
 
398
 
 
399
    bool Create(wxWindow *parent,
 
400
                wxWindowID winid,
 
401
                const wxPoint& pos = wxDefaultPosition,
 
402
                const wxSize& size = wxDefaultSize,
 
403
                long style = wxScrolledWindowStyle,
 
404
                const wxString& name = wxPanelNameStr)
 
405
    {
 
406
        m_targetWindow = this;
 
407
 
 
408
#ifdef __WXMAC__
 
409
        this->MacSetClipChildren(true);
 
410
#endif
 
411
 
 
412
        // by default, we're scrollable in both directions (but if one of the
 
413
        // styles is specified explicitly, we shouldn't add the other one
 
414
        // automatically)
 
415
        if ( !(style & (wxHSCROLL | wxVSCROLL)) )
 
416
            style |= wxHSCROLL | wxVSCROLL;
 
417
 
 
418
#ifdef __WXOSX__
 
419
        bool retval = T::Create(parent, winid, pos, size, style, name);
 
420
        if ( retval && (style & wxALWAYS_SHOW_SB) )
 
421
            ShowScrollbars(wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS);
 
422
        return retval;
 
423
#else
 
424
        if ( style & wxALWAYS_SHOW_SB )
 
425
            ShowScrollbars(wxSHOW_SB_ALWAYS, wxSHOW_SB_ALWAYS);
 
426
 
 
427
        return T::Create(parent, winid, pos, size, style, name);
 
428
#endif
 
429
    }
 
430
 
 
431
#ifdef __WXMSW__
 
432
    // we need to return a special WM_GETDLGCODE value to process just the
 
433
    // arrows but let the other navigation characters through
 
434
    virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
 
435
    {
 
436
        return FilterMSWWindowProc(nMsg, T::MSWWindowProc(nMsg, wParam, lParam));
 
437
    }
 
438
 
 
439
    // Take into account the scroll origin.
 
440
    virtual void MSWAdjustBrushOrg(int* xOrg, int* yOrg) const
 
441
    {
 
442
        CalcUnscrolledPosition(*xOrg, *yOrg, xOrg, yOrg);
 
443
    }
 
444
#endif // __WXMSW__
 
445
 
 
446
    WX_FORWARD_TO_SCROLL_HELPER()
 
447
 
 
448
protected:
 
449
    virtual wxSize DoGetBestSize() const
 
450
    {
 
451
        return FilterBestSize(this, this, T::DoGetBestSize());
 
452
    }
 
453
 
 
454
private:
 
455
    // VC++ 6 gives warning for the declaration of template member function
 
456
    // without definition
 
457
#ifndef __VISUALC6__
 
458
    wxDECLARE_NO_COPY_CLASS(wxScrolled);
 
459
#endif
 
460
};
 
461
 
 
462
#ifdef __VISUALC6__
 
463
    // disable the warning about non dll-interface class used as base for
 
464
    // dll-interface class: it's harmless in this case
 
465
    #pragma warning(push)
 
466
    #pragma warning(disable:4275)
 
467
#endif
 
468
 
 
469
// for compatibility with existing code, we provide wxScrolledWindow
 
470
// "typedef" for wxScrolled<wxPanel>. It's not a real typedef because we
 
471
// want wxScrolledWindow to show in wxRTTI information (the class is widely
 
472
// used and likelihood of its wxRTTI information being used too is high):
 
473
class WXDLLIMPEXP_CORE wxScrolledWindow : public wxScrolled<wxPanel>
 
474
{
 
475
public:
 
476
    wxScrolledWindow() : wxScrolled<wxPanel>() {}
 
477
    wxScrolledWindow(wxWindow *parent,
 
478
                     wxWindowID winid = wxID_ANY,
 
479
                     const wxPoint& pos = wxDefaultPosition,
 
480
                     const wxSize& size = wxDefaultSize,
 
481
                     long style = wxScrolledWindowStyle,
 
482
                     const wxString& name = wxPanelNameStr)
 
483
        : wxScrolled<wxPanel>(parent, winid, pos, size, style, name) {}
 
484
 
 
485
    DECLARE_DYNAMIC_CLASS_NO_COPY(wxScrolledWindow)
 
486
};
 
487
 
 
488
typedef wxScrolled<wxWindow> wxScrolledCanvas;
 
489
 
 
490
#ifdef __VISUALC6__
 
491
    #pragma warning(pop)
 
492
#endif
 
493
 
 
494
#endif // _WX_SCROLWIN_H_BASE_