OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [wxwin/] [ecscrolwin.cpp] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/////////////////////////////////////////////////////////////////////////////
2
// Name:        ecscrolwin.cpp
3
// Purpose:     ecScrolledWindow implementation
4
// Author:      Julian Smart
5
// Modified by:
6
// Created:     01/02/97
7
// RCS-ID:      $Id: ecscrolwin.cpp,v 1.3 2002/02/28 16:39:37 julians Exp $
8
// Copyright:   (c) Julian Smart and Markus Holzem
9
// Licence:     wxWindows license
10
/////////////////////////////////////////////////////////////////////////////
11
 
12
// ============================================================================
13
// declarations
14
// ============================================================================
15
 
16
// ----------------------------------------------------------------------------
17
// headers
18
// ----------------------------------------------------------------------------
19
 
20
#ifdef __GNUG__
21
    #pragma implementation "ecscrolwin.h"
22
#endif
23
 
24
#ifdef __VMS
25
#define XtDisplay XTDISPLAY
26
#endif
27
 
28
// Includes other headers for precompiled compilation
29
#include "ecpch.h"
30
 
31
#ifdef __BORLANDC__
32
    #pragma hdrstop
33
#endif
34
 
35
#include "wx/utils.h"
36
#include "wx/dcclient.h"
37
#include "wx/panel.h"
38
 
39
#include "ecscrolwin.h"
40
 
41
#ifdef __WXMSW__
42
    #include "windows.h"
43
#endif
44
 
45
#ifdef __WXMOTIF__
46
// For wxRETAINED implementation
47
#ifdef __VMS__ //VMS's Xm.h is not (yet) compatible with C++
48
               //This code switches off the compiler warnings
49
# pragma message disable nosimpint
50
#endif
51
#include <Xm/Xm.h>
52
#ifdef __VMS__
53
# pragma message enable nosimpint
54
#endif
55
#endif
56
 
57
#if !ecUSE_OWN_SCROLLED_WINDOW
58
 
59
IMPLEMENT_CLASS(ecScrolledWindow, wxScrolledWindow)
60
 
61
#else
62
 
63
// ----------------------------------------------------------------------------
64
// event tables
65
// ----------------------------------------------------------------------------
66
 
67
BEGIN_EVENT_TABLE(ecScrolledWindow, wxPanel)
68
    EVT_SCROLLWIN(ecScrolledWindow::OnScroll)
69
    EVT_SIZE(ecScrolledWindow::OnSize)
70
    EVT_PAINT(ecScrolledWindow::OnPaint)
71
    EVT_CHAR(ecScrolledWindow::OnChar)
72
END_EVENT_TABLE()
73
 
74
IMPLEMENT_DYNAMIC_CLASS(ecScrolledWindow, wxPanel)
75
 
76
// ============================================================================
77
// implementation
78
// ============================================================================
79
 
80
// ----------------------------------------------------------------------------
81
// ecScrolledWindow creation
82
// ----------------------------------------------------------------------------
83
 
84
ecScrolledWindow::ecScrolledWindow()
85
{
86
    m_xScrollPixelsPerLine = 0;
87
    m_yScrollPixelsPerLine = 0;
88
    m_xScrollingEnabled = TRUE;
89
    m_yScrollingEnabled = TRUE;
90
    m_xScrollPosition = 0;
91
    m_yScrollPosition = 0;
92
    m_xScrollLines = 0;
93
    m_yScrollLines = 0;
94
    m_xScrollLinesPerPage = 0;
95
    m_yScrollLinesPerPage = 0;
96
    m_scaleX = 1.0;
97
    m_scaleY = 1.0;
98
    m_targetWindow = (wxWindow*) NULL;
99
}
100
 
101
bool ecScrolledWindow::Create(wxWindow *parent,
102
                              wxWindowID id,
103
                              const wxPoint& pos,
104
                              const wxSize& size,
105
                              long style,
106
                              const wxString& name)
107
{
108
    m_xScrollPixelsPerLine = 0;
109
    m_yScrollPixelsPerLine = 0;
110
    m_xScrollingEnabled = TRUE;
111
    m_yScrollingEnabled = TRUE;
112
    m_xScrollPosition = 0;
113
    m_yScrollPosition = 0;
114
    m_xScrollLines = 0;
115
    m_yScrollLines = 0;
116
    m_xScrollLinesPerPage = 0;
117
    m_yScrollLinesPerPage = 0;
118
    m_scaleX = 1.0;
119
    m_scaleY = 1.0;
120
 
121
    m_targetWindow = this;
122
 
123
    bool ok = wxPanel::Create(parent, id, pos, size, style, name);
124
 
125
#if defined(__WXMSW__) && (wxVERSION_NUMBER < 2302)
126
    // we need to process arrows ourselves for scrolling
127
    m_lDlgCode |= DLGC_WANTARROWS;
128
#endif // __WXMSW__
129
 
130
    return ok;
131
}
132
 
133
ecScrolledWindow::~ecScrolledWindow()
134
{
135
}
136
 
137
// ----------------------------------------------------------------------------
138
// setting scrolling parameters
139
// ----------------------------------------------------------------------------
140
 
141
/*
142
 * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
143
 * noUnitsX/noUnitsY:        : no. units per scrollbar
144
 */
145
void ecScrolledWindow::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY,
146
               int noUnitsX, int noUnitsY,
147
               int xPos, int yPos, bool noRefresh )
148
{
149
    int xpos, ypos;
150
 
151
    CalcUnscrolledPosition(xPos, yPos, &xpos, &ypos);
152
    bool do_refresh =
153
    (
154
      (noUnitsX != 0 && m_xScrollLines == 0) ||
155
      (noUnitsX < m_xScrollLines && xpos > pixelsPerUnitX*noUnitsX) ||
156
 
157
      (noUnitsY != 0 && m_yScrollLines == 0) ||
158
      (noUnitsY < m_yScrollLines && ypos > pixelsPerUnitY*noUnitsY) ||
159
      (xPos != m_xScrollPosition) ||
160
      (yPos != m_yScrollPosition)
161
//       (pixelsPerUnitX != m_xScrollPixelsPerLine) ||
162
//       (pixelsPerUnitY != m_yScrollPixelsPerLine)
163
    );
164
 
165
    m_xScrollPixelsPerLine = pixelsPerUnitX;
166
    m_yScrollPixelsPerLine = pixelsPerUnitY;
167
    m_xScrollPosition = xPos;
168
    m_yScrollPosition = yPos;
169
    m_xScrollLines = noUnitsX;
170
    m_yScrollLines = noUnitsY;
171
 
172
#ifdef __WXMOTIF__
173
    // Sorry, some Motif-specific code to implement a backing pixmap
174
    // for the wxRETAINED style. Implementing a backing store can't
175
    // be entirely generic because it relies on the wxWindowDC implementation
176
    // to duplicate X drawing calls for the backing pixmap.
177
 
178
    if ((m_windowStyle & wxRETAINED) == wxRETAINED)
179
    {
180
        Display* dpy = XtDisplay((Widget) GetMainWidget());
181
 
182
        int totalPixelWidth = m_xScrollLines * m_xScrollPixelsPerLine;
183
        int totalPixelHeight = m_yScrollLines * m_yScrollPixelsPerLine;
184
        if (m_backingPixmap &&
185
           !((m_pixmapWidth == totalPixelWidth) &&
186
             (m_pixmapHeight == totalPixelHeight)))
187
        {
188
            XFreePixmap (dpy, (Pixmap) m_backingPixmap);
189
            m_backingPixmap = (WXPixmap) 0;
190
        }
191
 
192
        if (!m_backingPixmap &&
193
           (noUnitsX != 0) && (noUnitsY != 0))
194
        {
195
            int depth = wxDisplayDepth();
196
            m_pixmapWidth = totalPixelWidth;
197
            m_pixmapHeight = totalPixelHeight;
198
            m_backingPixmap = (WXPixmap) XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
199
            m_pixmapWidth, m_pixmapHeight, depth);
200
        }
201
 
202
    }
203
#endif // Motif
204
 
205
    AdjustScrollbars();
206
 
207
    if (do_refresh && !noRefresh)
208
        m_targetWindow->Refresh();
209
 
210
#ifdef __WXMSW__
211
    // GRG: if this turns out to be really necessary, we could
212
    //   at least move it to the above if { ... } so that it is
213
    //   only done if noRefresh = FALSE (the default). OTOH, if
214
    //   this doesn't break anything, which seems to be the
215
    //   case, we could just leave it out.
216
 
217
    // Necessary?
218
    // UpdateWindow ((HWND) m_targetWindow->GetHWND());
219
#endif
220
#ifdef __WXMAC__
221
    m_targetWindow->MacUpdateImmediately() ;
222
#endif
223
}
224
 
225
// ----------------------------------------------------------------------------
226
// target window handling
227
// ----------------------------------------------------------------------------
228
 
229
void ecScrolledWindow::SetTargetWindow( wxWindow *target )
230
{
231
    wxASSERT_MSG( target, wxT("target window must not be NULL") );
232
    m_targetWindow = target;
233
}
234
 
235
wxWindow *ecScrolledWindow::GetTargetWindow()
236
{
237
    return m_targetWindow;
238
}
239
 
240
// ----------------------------------------------------------------------------
241
// scrolling implementation itself
242
// ----------------------------------------------------------------------------
243
 
244
void ecScrolledWindow::OnScroll(wxScrollWinEvent& event)
245
{
246
    int orient = event.GetOrientation();
247
 
248
    int nScrollInc = CalcScrollInc(event);
249
    if (nScrollInc == 0) return;
250
 
251
    if (orient == wxHORIZONTAL)
252
    {
253
        int newPos = m_xScrollPosition + nScrollInc;
254
        SetScrollPos(wxHORIZONTAL, newPos, TRUE );
255
    }
256
    else
257
    {
258
        int newPos = m_yScrollPosition + nScrollInc;
259
        SetScrollPos(wxVERTICAL, newPos, TRUE );
260
    }
261
 
262
    if (orient == wxHORIZONTAL)
263
    {
264
        m_xScrollPosition += nScrollInc;
265
    }
266
    else
267
    {
268
        m_yScrollPosition += nScrollInc;
269
    }
270
 
271
    if (orient == wxHORIZONTAL)
272
    {
273
       if (m_xScrollingEnabled)
274
            m_targetWindow->ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, (const wxRect *) NULL);
275
       else
276
            m_targetWindow->Refresh();
277
    }
278
    else
279
    {
280
        if (m_yScrollingEnabled)
281
            m_targetWindow->ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, (const wxRect *) NULL);
282
        else
283
            m_targetWindow->Refresh();
284
    }
285
#ifdef __WXMAC__
286
    m_targetWindow->MacUpdateImmediately() ;
287
#endif
288
}
289
 
290
int ecScrolledWindow::CalcScrollInc(wxScrollWinEvent& event)
291
{
292
    int pos = event.GetPosition();
293
    int orient = event.GetOrientation();
294
 
295
    int nScrollInc = 0;
296
    if (event.GetEventType() == wxEVT_SCROLLWIN_TOP)
297
    {
298
            if (orient == wxHORIZONTAL)
299
                nScrollInc = - m_xScrollPosition;
300
            else
301
                nScrollInc = - m_yScrollPosition;
302
    } else
303
    if (event.GetEventType() == wxEVT_SCROLLWIN_BOTTOM)
304
    {
305
            if (orient == wxHORIZONTAL)
306
                nScrollInc = m_xScrollLines - m_xScrollPosition;
307
            else
308
                nScrollInc = m_yScrollLines - m_yScrollPosition;
309
    } else
310
    if (event.GetEventType() == wxEVT_SCROLLWIN_LINEUP)
311
    {
312
            nScrollInc = -1;
313
    } else
314
    if (event.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN)
315
    {
316
            nScrollInc = 1;
317
    } else
318
    if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEUP)
319
    {
320
            if (orient == wxHORIZONTAL)
321
                nScrollInc = -GetScrollPageSize(wxHORIZONTAL);
322
            else
323
                nScrollInc = -GetScrollPageSize(wxVERTICAL);
324
    } else
325
    if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN)
326
    {
327
            if (orient == wxHORIZONTAL)
328
                nScrollInc = GetScrollPageSize(wxHORIZONTAL);
329
            else
330
                nScrollInc = GetScrollPageSize(wxVERTICAL);
331
    } else
332
    if ((event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK) ||
333
        (event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE))
334
    {
335
            if (orient == wxHORIZONTAL)
336
                nScrollInc = pos - m_xScrollPosition;
337
            else
338
                nScrollInc = pos - m_yScrollPosition;
339
    }
340
 
341
    if (orient == wxHORIZONTAL)
342
    {
343
        if (m_xScrollPixelsPerLine > 0)
344
        {
345
            int w, h;
346
            m_targetWindow->GetClientSize(&w, &h);
347
 
348
            int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
349
            int noPositions = (int) ( ((nMaxWidth - w)/(double)m_xScrollPixelsPerLine) + 0.5 );
350
            if (noPositions < 0)
351
                noPositions = 0;
352
 
353
            if ( (m_xScrollPosition + nScrollInc) < 0 )
354
                nScrollInc = -m_xScrollPosition; // As -ve as we can go
355
            else if ( (m_xScrollPosition + nScrollInc) > noPositions )
356
                nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go
357
        }
358
        else
359
            m_targetWindow->Refresh();
360
    }
361
    else
362
    {
363
        if (m_yScrollPixelsPerLine > 0)
364
        {
365
            int w, h;
366
            m_targetWindow->GetClientSize(&w, &h);
367
 
368
            int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
369
            int noPositions = (int) ( ((nMaxHeight - h)/(double)m_yScrollPixelsPerLine) + 0.5 );
370
            if (noPositions < 0)
371
                noPositions = 0;
372
 
373
            if ( (m_yScrollPosition + nScrollInc) < 0 )
374
                nScrollInc = -m_yScrollPosition; // As -ve as we can go
375
            else if ( (m_yScrollPosition + nScrollInc) > noPositions )
376
                nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go
377
        }
378
        else
379
            m_targetWindow->Refresh();
380
    }
381
 
382
    return nScrollInc;
383
}
384
 
385
// Adjust the scrollbars - new version.
386
void ecScrolledWindow::AdjustScrollbars()
387
{
388
    int w, h;
389
    m_targetWindow->GetClientSize(&w, &h);
390
 
391
    int oldXScroll = m_xScrollPosition;
392
    int oldYScroll = m_yScrollPosition;
393
 
394
    if (m_xScrollLines > 0)
395
    {
396
        // Calculate page size i.e. number of scroll units you get on the
397
        // current client window
398
        int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
399
        if (noPagePositions < 1) noPagePositions = 1;
400
 
401
        // Correct position if greater than extent of canvas minus
402
        // the visible portion of it or if below zero
403
        m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition);
404
        m_xScrollPosition = wxMax( 0, m_xScrollPosition );
405
 
406
        SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, m_xScrollLines);
407
        // The amount by which we scroll when paging
408
        SetScrollPageSize(wxHORIZONTAL, noPagePositions);
409
    }
410
    else
411
    {
412
        m_xScrollPosition = 0;
413
        SetScrollbar (wxHORIZONTAL, 0, 0, 0, FALSE);
414
    }
415
 
416
    if (m_yScrollLines > 0)
417
    {
418
        // Calculate page size i.e. number of scroll units you get on the
419
        // current client window
420
        int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
421
        if (noPagePositions < 1) noPagePositions = 1;
422
 
423
        // Correct position if greater than extent of canvas minus
424
        // the visible portion of it or if below zero
425
        m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
426
        m_yScrollPosition = wxMax( 0, m_yScrollPosition );
427
 
428
        SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, m_yScrollLines);
429
        // The amount by which we scroll when paging
430
        SetScrollPageSize(wxVERTICAL, noPagePositions);
431
    }
432
    else
433
    {
434
        m_yScrollPosition = 0;
435
        SetScrollbar (wxVERTICAL, 0, 0, 0, FALSE);
436
    }
437
 
438
    if (oldXScroll != m_xScrollPosition)
439
    {
440
       if (m_xScrollingEnabled)
441
            m_targetWindow->ScrollWindow( m_xScrollPixelsPerLine * (oldXScroll-m_xScrollPosition), 0, (const wxRect *) NULL );
442
       else
443
            m_targetWindow->Refresh();
444
    }
445
 
446
    if (oldYScroll != m_yScrollPosition)
447
    {
448
        if (m_yScrollingEnabled)
449
            m_targetWindow->ScrollWindow( 0, m_yScrollPixelsPerLine * (oldYScroll-m_yScrollPosition), (const wxRect *) NULL );
450
        else
451
            m_targetWindow->Refresh();
452
    }
453
}
454
 
455
// Override this function if you don't want to have ecScrolledWindow
456
// automatically change the origin according to the scroll position.
457
void ecScrolledWindow::PrepareDC(wxDC& dc)
458
{
459
    dc.SetDeviceOrigin( -m_xScrollPosition * m_xScrollPixelsPerLine,
460
                        -m_yScrollPosition * m_yScrollPixelsPerLine );
461
    dc.SetUserScale( m_scaleX, m_scaleY );
462
}
463
 
464
#if WXWIN_COMPATIBILITY
465
void ecScrolledWindow::GetScrollUnitsPerPage (int *x_page, int *y_page) const
466
{
467
      *x_page = GetScrollPageSize(wxHORIZONTAL);
468
      *y_page = GetScrollPageSize(wxVERTICAL);
469
}
470
 
471
void ecScrolledWindow::CalcUnscrolledPosition(int x, int y, float *xx, float *yy) const
472
{
473
    if ( xx )
474
        *xx = (float)(x + m_xScrollPosition * m_xScrollPixelsPerLine);
475
    if ( yy )
476
        *yy = (float)(y + m_yScrollPosition * m_yScrollPixelsPerLine);
477
}
478
#endif // WXWIN_COMPATIBILITY
479
 
480
void ecScrolledWindow::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
481
{
482
    if ( x_unit )
483
        *x_unit = m_xScrollPixelsPerLine;
484
    if ( y_unit )
485
        *y_unit = m_yScrollPixelsPerLine;
486
}
487
 
488
int ecScrolledWindow::GetScrollPageSize(int orient) const
489
{
490
    if ( orient == wxHORIZONTAL )
491
        return m_xScrollLinesPerPage;
492
    else
493
        return m_yScrollLinesPerPage;
494
}
495
 
496
void ecScrolledWindow::SetScrollPageSize(int orient, int pageSize)
497
{
498
    if ( orient == wxHORIZONTAL )
499
        m_xScrollLinesPerPage = pageSize;
500
    else
501
        m_yScrollLinesPerPage = pageSize;
502
}
503
 
504
/*
505
 * Scroll to given position (scroll position, not pixel position)
506
 */
507
void ecScrolledWindow::Scroll( int x_pos, int y_pos )
508
{
509
    if (!m_targetWindow)
510
        return;
511
 
512
    if (((x_pos == -1) || (x_pos == m_xScrollPosition)) &&
513
        ((y_pos == -1) || (y_pos == m_yScrollPosition))) return;
514
 
515
    int w, h;
516
    m_targetWindow->GetClientSize(&w, &h);
517
 
518
    if ((x_pos != -1) && (m_xScrollPixelsPerLine))
519
    {
520
        int old_x = m_xScrollPosition;
521
        m_xScrollPosition = x_pos;
522
 
523
        // Calculate page size i.e. number of scroll units you get on the
524
        // current client window
525
        int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
526
        if (noPagePositions < 1) noPagePositions = 1;
527
 
528
        // Correct position if greater than extent of canvas minus
529
        // the visible portion of it or if below zero
530
        m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition );
531
        m_xScrollPosition = wxMax( 0, m_xScrollPosition );
532
 
533
        if (old_x != m_xScrollPosition) {
534
            m_targetWindow->SetScrollPos( wxHORIZONTAL, m_xScrollPosition, TRUE );
535
            m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0 );
536
        }
537
    }
538
    if ((y_pos != -1) && (m_yScrollPixelsPerLine))
539
    {
540
        int old_y = m_yScrollPosition;
541
        m_yScrollPosition = y_pos;
542
 
543
        // Calculate page size i.e. number of scroll units you get on the
544
        // current client window
545
        int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
546
        if (noPagePositions < 1) noPagePositions = 1;
547
 
548
        // Correct position if greater than extent of canvas minus
549
        // the visible portion of it or if below zero
550
        m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
551
        m_yScrollPosition = wxMax( 0, m_yScrollPosition );
552
 
553
        if (old_y != m_yScrollPosition) {
554
            m_targetWindow->SetScrollPos( wxVERTICAL, m_yScrollPosition, TRUE );
555
            m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine );
556
        }
557
    }
558
 
559
#ifdef __WXMAC__
560
    m_targetWindow->MacUpdateImmediately();
561
#endif
562
}
563
 
564
void ecScrolledWindow::EnableScrolling (bool x_scroll, bool y_scroll)
565
{
566
    m_xScrollingEnabled = x_scroll;
567
    m_yScrollingEnabled = y_scroll;
568
}
569
 
570
void ecScrolledWindow::GetVirtualSize (int *x, int *y) const
571
{
572
    if ( x )
573
        *x = m_xScrollPixelsPerLine * m_xScrollLines;
574
    if ( y )
575
        *y = m_yScrollPixelsPerLine * m_yScrollLines;
576
}
577
 
578
// Where the current view starts from
579
void ecScrolledWindow::GetViewStart (int *x, int *y) const
580
{
581
    if ( x )
582
        *x = m_xScrollPosition;
583
    if ( y )
584
        *y = m_yScrollPosition;
585
}
586
 
587
void ecScrolledWindow::CalcScrolledPosition(int x, int y, int *xx, int *yy) const
588
{
589
    if ( xx )
590
        *xx = x - m_xScrollPosition * m_xScrollPixelsPerLine;
591
    if ( yy )
592
        *yy = y - m_yScrollPosition * m_yScrollPixelsPerLine;
593
}
594
 
595
void ecScrolledWindow::CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
596
{
597
    if ( xx )
598
        *xx = x + m_xScrollPosition * m_xScrollPixelsPerLine;
599
    if ( yy )
600
        *yy = y + m_yScrollPosition * m_yScrollPixelsPerLine;
601
}
602
 
603
// ----------------------------------------------------------------------------
604
// event handlers
605
// ----------------------------------------------------------------------------
606
 
607
// Default OnSize resets scrollbars, if any
608
void ecScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event))
609
{
610
#if wxUSE_CONSTRAINTS
611
    if (GetAutoLayout())
612
        Layout();
613
#endif
614
 
615
    AdjustScrollbars();
616
}
617
 
618
// This calls OnDraw, having adjusted the origin according to the current
619
// scroll position
620
void ecScrolledWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
621
{
622
    wxPaintDC dc(this);
623
    PrepareDC(dc);
624
 
625
    OnDraw(dc);
626
}
627
 
628
// kbd handling: notice that we use OnChar() and not OnKeyDown() for
629
// compatibility here - if we used OnKeyDown(), the programs which process
630
// arrows themselves in their OnChar() would never get the message and like
631
// this they always have the priority
632
void ecScrolledWindow::OnChar(wxKeyEvent& event)
633
{
634
    int stx, sty,       // view origin
635
        szx, szy,       // view size (total)
636
        clix, cliy;     // view size (on screen)
637
 
638
    ViewStart(&stx, &sty);
639
    GetClientSize(&clix, &cliy);
640
    GetVirtualSize(&szx, &szy);
641
 
642
    if( m_xScrollPixelsPerLine )
643
    {
644
        clix /= m_xScrollPixelsPerLine;
645
        szx /= m_xScrollPixelsPerLine;
646
    }
647
    else
648
    {
649
        clix = 0;
650
        szx = -1;
651
    }
652
    if( m_yScrollPixelsPerLine )
653
    {
654
        cliy /= m_yScrollPixelsPerLine;
655
        szy /= m_yScrollPixelsPerLine;
656
    }
657
    else
658
    {
659
        cliy = 0;
660
        szy = -1;
661
    }
662
 
663
    int dsty;
664
#if wxCHECK_VERSION(2, 6, 0)
665
    switch ( event.GetKeyCode() )
666
#else
667
    switch ( event.KeyCode() )
668
#endif
669
    {
670
        case WXK_PAGEUP:
671
        case WXK_PRIOR:
672
            dsty = sty - (5 * cliy / 6);
673
            Scroll(-1, (dsty == -1) ? 0 : dsty);
674
            break;
675
 
676
        case WXK_PAGEDOWN:
677
        case WXK_NEXT:
678
            Scroll(-1, sty + (5 * cliy / 6));
679
            break;
680
 
681
        case WXK_HOME:
682
            Scroll(0, event.ControlDown() ? 0 : -1);
683
            break;
684
 
685
        case WXK_END:
686
            Scroll(szx - clix, event.ControlDown() ? szy - cliy : -1);
687
            break;
688
 
689
        case WXK_UP:
690
            Scroll(-1, sty - 1);
691
            break;
692
 
693
        case WXK_DOWN:
694
            Scroll(-1, sty + 1);
695
            break;
696
 
697
        case WXK_LEFT:
698
            Scroll(stx - 1, -1);
699
            break;
700
 
701
        case WXK_RIGHT:
702
            Scroll(stx + 1, -1);
703
            break;
704
 
705
        default:
706
            // not for us
707
            event.Skip();
708
    }
709
}
710
#endif
711
// ecUSE_OWN_SCROLLED_WINDOW

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.