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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/////////////////////////////////////////////////////////////////////////////
2
// Name:        splittree.cpp
3
// Purpose:     Classes to achieve a remotely-scrolled tree in a splitter
4
//              window that can be scrolled by a scrolled window higher in the
5
//              hierarchy
6
// Author:      Julian Smart
7
// Modified by:
8
// Created:     8/7/2000
9
// RCS-ID:      $Id: splittree.cpp,v 1.9 2002/02/28 18:30:35 julians Exp $
10
// Copyright:   (c) Julian Smart
11
//
12
// This program is part of the eCos host tools.
13
//
14
// This program is free software; you can redistribute it and/or modify it
15
// under the terms of the GNU General Public License as published by the Free
16
// Software Foundation; either version 2 of the License, or (at your option)
17
// any later version.
18
//
19
// This program is distributed in the hope that it will be useful, but WITHOUT
20
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
22
// more details.
23
//
24
// You should have received a copy of the GNU General Public License along with
25
// this program; if not, write to the Free Software Foundation, Inc.,
26
// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27
//
28
/////////////////////////////////////////////////////////////////////////////
29
 
30
// ============================================================================
31
// declarations
32
// ============================================================================
33
 
34
// ----------------------------------------------------------------------------
35
// headers
36
// ----------------------------------------------------------------------------
37
#ifdef __GNUG__
38
#pragma implementation "splittree.h"
39
#endif
40
 
41
// For compilers that support precompilation, includes "wx/wx.h".
42
#include "ecpch.h"
43
 
44
#ifdef __WXMSW__
45
#include "wx/msw/private.h"
46
#endif
47
 
48
#ifdef __BORLANDC__
49
#pragma hdrstop
50
#endif
51
 
52
#include "wx/generic/treectlg.h"
53
 
54
#include "splittree.h"
55
#include <math.h>
56
 
57
/*
58
* wxRemotelyScrolledTreeCtrl
59
*/
60
 
61
#if USE_GENERIC_TREECTRL
62
IMPLEMENT_CLASS(wxRemotelyScrolledTreeCtrl, wxGenericTreeCtrl)
63
#else
64
IMPLEMENT_CLASS(wxRemotelyScrolledTreeCtrl, wxTreeCtrl)
65
#endif
66
 
67
#if USE_GENERIC_TREECTRL
68
BEGIN_EVENT_TABLE(wxRemotelyScrolledTreeCtrl, wxGenericTreeCtrl)
69
#else
70
BEGIN_EVENT_TABLE(wxRemotelyScrolledTreeCtrl, wxTreeCtrl)
71
#endif
72
EVT_SIZE(wxRemotelyScrolledTreeCtrl::OnSize)
73
EVT_TREE_ITEM_EXPANDED(-1, wxRemotelyScrolledTreeCtrl::OnExpand)
74
EVT_TREE_ITEM_COLLAPSED(-1, wxRemotelyScrolledTreeCtrl::OnExpand)
75
EVT_SCROLLWIN(wxRemotelyScrolledTreeCtrl::OnScroll)
76
END_EVENT_TABLE()
77
 
78
wxRemotelyScrolledTreeCtrl::wxRemotelyScrolledTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pt,
79
                                                       const wxSize& sz, long style):
80
    wxTreeCtrl(parent, id, pt, sz, style
81
#if wxVERSION_NUMBER > 2301
82
               & ~wxTR_ROW_LINES
83
#endif
84
               )
85
{
86
    m_companionWindow = NULL;
87
}
88
 
89
wxRemotelyScrolledTreeCtrl::~wxRemotelyScrolledTreeCtrl()
90
{
91
}
92
 
93
void wxRemotelyScrolledTreeCtrl::HideVScrollbar()
94
{
95
#ifdef __WXMSW__
96
    if (!IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
97
    {
98
        ::ShowScrollBar((HWND) GetHWND(), SB_VERT, FALSE);
99
    }
100
    else
101
#endif
102
    {
103
        // Implicit in overriding SetScrollbars
104
    }
105
}
106
 
107
// Number of pixels per user unit (0 or -1 for no scrollbar)
108
// Length of virtual canvas in user units
109
// Length of page in user units
110
void wxRemotelyScrolledTreeCtrl::SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
111
                                               int noUnitsX, int noUnitsY,
112
                                               int xPos, int yPos,
113
                                               bool noRefresh)
114
{
115
    if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
116
    {
117
        wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
118
        // Pass TRUE for noRefresh so that it doesn't
119
        // draw part of the tree as if the scroll view is
120
        // at zero vertically.
121
        win->wxGenericTreeCtrl::SetScrollbars(pixelsPerUnitX, pixelsPerUnitY, noUnitsX, 0, xPos, 0, /* noRefresh */ TRUE);
122
 
123
        ecScrolledWindow* scrolledWindow = GetScrolledWindow();
124
        if (scrolledWindow)
125
        {
126
            scrolledWindow->SetScrollbars(0, pixelsPerUnitY, 0, noUnitsY, 0, yPos, noRefresh);
127
        }
128
    }
129
}
130
 
131
// In case we're using the generic tree control.
132
int wxRemotelyScrolledTreeCtrl::GetScrollPos(int orient) const
133
{
134
    ecScrolledWindow* scrolledWindow = GetScrolledWindow();
135
 
136
    if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
137
    {
138
        wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
139
 
140
        if (orient == wxHORIZONTAL)
141
            return win->wxGenericTreeCtrl::GetScrollPos(orient);
142
        else
143
        {
144
            return scrolledWindow->GetScrollPos(orient);
145
        }
146
    }
147
    return 0;
148
}
149
 
150
 
151
// In case we're using the generic tree control.
152
// Get the view start
153
void wxRemotelyScrolledTreeCtrl::GetViewStart(int *x, int *y) const
154
{
155
    ecScrolledWindow* scrolledWindow = GetScrolledWindow();
156
 
157
    if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
158
    {
159
 
160
        wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
161
        int x1, y1, x2, y2;
162
        win->wxGenericTreeCtrl::GetViewStart(& x1, & y1);
163
        * x = x1; * y = y1;
164
        if (!scrolledWindow)
165
            return;
166
 
167
        scrolledWindow->GetViewStart(& x2, & y2);
168
        * y = y2;
169
    }
170
    else
171
    {
172
        // x is wrong since the horizontal scrollbar is controlled by the
173
        // tree control, but we probably don't need it.
174
        scrolledWindow->GetViewStart(x, y);
175
    }
176
}
177
 
178
// In case we're using the generic tree control.
179
void wxRemotelyScrolledTreeCtrl::PrepareDC(wxDC& dc)
180
{
181
    if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
182
    {
183
        ecScrolledWindow* scrolledWindow = GetScrolledWindow();
184
 
185
        wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
186
 
187
        int startX, startY;
188
        GetViewStart(& startX, & startY);
189
 
190
        int xppu1, yppu1, xppu2, yppu2;
191
        win->wxGenericTreeCtrl::GetScrollPixelsPerUnit(& xppu1, & yppu1);
192
        scrolledWindow->GetScrollPixelsPerUnit(& xppu2, & yppu2);
193
 
194
        dc.SetDeviceOrigin( -startX * xppu1, -startY * yppu2 );
195
        // dc.SetUserScale( win->GetScaleX(), win->GetScaleY() );
196
    }
197
}
198
 
199
// Scroll to the given line (in scroll units where each unit is
200
// the height of an item)
201
void wxRemotelyScrolledTreeCtrl::ScrollToLine(int posHoriz, int posVert)
202
{
203
#ifdef __WXMSW__
204
    if (!IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
205
    {
206
        UINT sbCode = SB_THUMBPOSITION;
207
        HWND vertScrollBar = 0;
208
#if wxCHECK_VERSION(2, 6, 0)
209
        MSWDefWindowProc((WXUINT) WM_VSCROLL, MAKELONG(sbCode, posVert), (WXLPARAM) vertScrollBar);
210
#else
211
        MSWDefWindowProc((WXUINT) WM_VSCROLL, MAKELONG(sbCode, posVert), (WXHWND) vertScrollBar);
212
#endif
213
    }
214
    else
215
#endif
216
    {
217
        wxGenericTreeCtrl* win = (wxGenericTreeCtrl*) this;
218
        win->Refresh();
219
        /* Doesn't work yet because scrolling is ignored by Scroll
220
        int xppu, yppu;
221
        wxScrolledWindow* scrolledWindow = GetScrolledWindow();
222
        if (scrolledWindow)
223
        {
224
        scrolledWindow->GetScrollPixelsPerUnit(& xppu, & yppu);
225
        win->Scroll(-1, posVert*yppu);
226
        }
227
        */
228
    }
229
}
230
 
231
void wxRemotelyScrolledTreeCtrl::OnSize(wxSizeEvent& event)
232
{
233
    HideVScrollbar();
234
    AdjustRemoteScrollbars();
235
    event.Skip();
236
}
237
 
238
void wxRemotelyScrolledTreeCtrl::OnExpand(wxTreeEvent& event)
239
{
240
    AdjustRemoteScrollbars();
241
    event.Skip();
242
 
243
    // If we don't have this, we get some bits of lines still remaining
244
    if (event.GetEventType() == wxEVT_COMMAND_TREE_ITEM_COLLAPSED)
245
        Refresh();
246
 
247
    // Pass on the event
248
    if (m_companionWindow)
249
        m_companionWindow->GetEventHandler()->ProcessEvent(event);
250
}
251
 
252
// Adjust the containing wxScrolledWindow's scrollbars appropriately
253
void wxRemotelyScrolledTreeCtrl::AdjustRemoteScrollbars()
254
{
255
    if (IsKindOf(CLASSINFO(wxGenericTreeCtrl)))
256
    {
257
        // This is for the generic tree control.
258
        // It calls SetScrollbars which has been overridden
259
        // to adjust the parent scrolled window vertical
260
        // scrollbar.
261
        ((wxGenericTreeCtrl*) this)->AdjustMyScrollbars();
262
        return;
263
    }
264
    else
265
    {
266
        // This is for the wxMSW tree control
267
        ecScrolledWindow* scrolledWindow = GetScrolledWindow();
268
        if (scrolledWindow)
269
        {
270
            wxRect itemRect;
271
            if (GetBoundingRect(GetRootItem(), itemRect))
272
            {
273
                // Actually, the real height seems to be 1 less than reported
274
                // (e.g. 16 instead of 16)
275
                int itemHeight = itemRect.GetHeight() - 1;
276
 
277
                int w, h;
278
                GetClientSize(&w, &h);
279
 
280
                wxRect rect(0, 0, 0, 0);
281
                CalcTreeSize(rect);
282
 
283
                double f = ((double) (rect.GetHeight()) / (double) itemHeight)  ;
284
                int treeViewHeight = (int) ceil(f);
285
 
286
                int scrollPixelsPerLine = itemHeight;
287
                int scrollPos = - (itemRect.y / itemHeight);
288
 
289
                scrolledWindow->SetScrollbars(0, scrollPixelsPerLine, 0, treeViewHeight, 0, scrollPos);
290
 
291
                // Ensure that when a scrollbar becomes hidden or visible,
292
                // the contained window sizes are right.
293
                // Problem: this is called too early (?)
294
                wxSizeEvent event(scrolledWindow->GetSize(), scrolledWindow->GetId());
295
                scrolledWindow->GetEventHandler()->ProcessEvent(event);
296
            }
297
        }
298
    }
299
}
300
 
301
 
302
// Calculate the area that contains both rectangles
303
static wxRect CombineRectangles(const wxRect& rect1, const wxRect& rect2)
304
{
305
    wxRect rect;
306
 
307
    int right1 = rect1.GetRight();
308
    int bottom1 = rect1.GetBottom();
309
    int right2 = rect2.GetRight();
310
    int bottom2 = rect2.GetBottom();
311
 
312
    wxPoint topLeft = wxPoint(wxMin(rect1.x, rect2.x), wxMin(rect1.y, rect2.y));
313
    wxPoint bottomRight = wxPoint(wxMax(right1, right2), wxMax(bottom1, bottom2));
314
 
315
    rect.x = topLeft.x; rect.y = topLeft.y;
316
    rect.SetRight(bottomRight.x);
317
    rect.SetBottom(bottomRight.y);
318
 
319
    return rect;
320
}
321
 
322
 
323
// Calculate the tree overall size so we can set the scrollbar
324
// correctly
325
 
326
// static int g_count = 0;
327
 
328
void wxRemotelyScrolledTreeCtrl::CalcTreeSize(wxRect& rect)
329
{
330
    //    g_count = 0;
331
    CalcTreeSize(GetRootItem(), rect);
332
}
333
 
334
void wxRemotelyScrolledTreeCtrl::CalcTreeSize(const wxTreeItemId& id, wxRect& rect)
335
{
336
    // More efficient implementation would be to find the last item (but how?)
337
    // Q: is the bounding rect relative to the top of the virtual tree workspace
338
    // or the top of the window? How would we convert?
339
    wxRect itemSize;
340
    if (GetBoundingRect(id, itemSize))
341
    {
342
        rect = CombineRectangles(rect, itemSize);
343
    }
344
 
345
#if wxCHECK_VERSION(2, 6, 0)
346
    wxTreeItemIdValue cookie;
347
    wxTreeItemId childId = GetFirstChild(id, cookie);
348
 
349
    while (childId.IsOk())
350
#else
351
    long cookie;
352
    wxTreeItemId childId = GetFirstChild(id, cookie);
353
 
354
    while (childId != 0)
355
#endif
356
    {
357
        CalcTreeSize(childId, rect);
358
        childId = GetNextChild(childId, cookie);
359
    }
360
}
361
 
362
// Find the scrolled window that contains this control
363
ecScrolledWindow* wxRemotelyScrolledTreeCtrl::GetScrolledWindow() const
364
{
365
    wxWindow* parent = wxWindow::GetParent();
366
    while (parent)
367
    {
368
        if (parent->IsKindOf(CLASSINFO(ecScrolledWindow)))
369
            return (ecScrolledWindow*) parent;
370
        parent = parent->GetParent();
371
    }
372
    return NULL;
373
}
374
 
375
void wxRemotelyScrolledTreeCtrl::OnScroll(wxScrollWinEvent& event)
376
{
377
    int orient = event.GetOrientation();
378
    if (orient == wxHORIZONTAL)
379
    {
380
        event.Skip();
381
        return;
382
    }
383
    ecScrolledWindow* scrollWin = GetScrolledWindow();
384
    if (!scrollWin)
385
        return;
386
 
387
    int x, y;
388
    scrollWin->GetViewStart(& x, & y);
389
 
390
    ScrollToLine(-1, y);
391
}
392
 
393
/*
394
* wxTreeCompanionWindow
395
*
396
* A window displaying values associated with tree control items.
397
*/
398
 
399
IMPLEMENT_CLASS(wxTreeCompanionWindow, wxWindow)
400
 
401
BEGIN_EVENT_TABLE(wxTreeCompanionWindow, wxWindow)
402
EVT_PAINT(wxTreeCompanionWindow::OnPaint)
403
EVT_SCROLLWIN(wxTreeCompanionWindow::OnScroll)
404
EVT_TREE_ITEM_EXPANDED(-1, wxTreeCompanionWindow::OnExpand)
405
EVT_TREE_ITEM_COLLAPSED(-1, wxTreeCompanionWindow::OnExpand)
406
END_EVENT_TABLE()
407
 
408
wxTreeCompanionWindow::wxTreeCompanionWindow(wxWindow* parent, wxWindowID id,
409
                                             const wxPoint& pos,
410
                                             const wxSize& sz,
411
                                             long style):
412
wxWindow(parent, id, pos, sz, style)
413
{
414
    m_treeCtrl = NULL;
415
}
416
 
417
void wxTreeCompanionWindow::DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect)
418
{
419
    if (m_treeCtrl)
420
    {
421
        wxString text = m_treeCtrl->GetItemText(id);
422
        dc.SetTextForeground(* wxBLACK);
423
        dc.SetBackgroundMode(wxTRANSPARENT);
424
 
425
        int textW, textH;
426
        dc.GetTextExtent(text, & textW, & textH);
427
 
428
        int x = 5;
429
        int y = rect.GetY() + wxMax(0, (rect.GetHeight() - textH) / 2);
430
 
431
        dc.DrawText(text, x, y);
432
    }
433
}
434
 
435
void wxTreeCompanionWindow::OnPaint(wxPaintEvent& event)
436
{
437
    wxPaintDC dc(this);
438
 
439
    if (!m_treeCtrl)
440
        return;
441
 
442
#if wxCHECK_VERSION(2, 6, 0)
443
    wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
444
    dc.SetPen(pen);
445
    dc.SetBrush(* wxTRANSPARENT_BRUSH);
446
    wxFont font(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
447
#else
448
    wxPen pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
449
    dc.SetPen(pen);
450
    dc.SetBrush(* wxTRANSPARENT_BRUSH);
451
    wxFont font(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
452
#endif
453
 
454
    dc.SetFont(font);
455
 
456
    wxSize clientSize = GetClientSize();
457
    wxRect itemRect;
458
    int cy=0;
459
    wxTreeItemId h, lastH;
460
    for(h=m_treeCtrl->GetFirstVisibleItem();h;h=m_treeCtrl->GetNextVisible(h))
461
    {
462
        if (m_treeCtrl->GetBoundingRect(h, itemRect))
463
        {
464
            cy = itemRect.GetTop();
465
            wxRect drawItemRect(0, cy, clientSize.x, itemRect.GetHeight());
466
 
467
            lastH = h;
468
 
469
            // Draw the actual item
470
            DrawItem(dc, h, drawItemRect);
471
            dc.DrawLine(0, cy, clientSize.x, cy);
472
        }
473
    }
474
    if (lastH.IsOk() && m_treeCtrl->GetBoundingRect(lastH, itemRect))
475
    {
476
        cy = itemRect.GetBottom();
477
        dc.DrawLine(0, cy, clientSize.x, cy);
478
    }
479
}
480
 
481
void wxTreeCompanionWindow::OnScroll(wxScrollWinEvent& event)
482
{
483
    int orient = event.GetOrientation();
484
    if (orient == wxHORIZONTAL)
485
    {
486
        event.Skip();
487
        return;
488
    }
489
    if (!m_treeCtrl)
490
        return;
491
 
492
    // TODO: scroll the window physically instead of just refreshing.
493
    Refresh(TRUE);
494
}
495
 
496
void wxTreeCompanionWindow::OnExpand(wxTreeEvent& event)
497
{
498
    // TODO: something more optimized than simply refresh the whole
499
    // window when the tree is expanded/collapsed. Tricky.
500
    Refresh();
501
}
502
 
503
/*
504
* wxThinSplitterWindow
505
*/
506
 
507
IMPLEMENT_CLASS(wxThinSplitterWindow, wxSplitterWindow)
508
 
509
BEGIN_EVENT_TABLE(wxThinSplitterWindow, wxSplitterWindow)
510
EVT_SIZE(wxThinSplitterWindow::OnSize)
511
// Not in older versions of wxWindows, unfortunately
512
#if 0
513
EVT_SPLITTER_DOUBLECLICKED(-1, wxThinSplitterWindow::OnDoubleClickSash)
514
#endif
515
END_EVENT_TABLE()
516
 
517
wxThinSplitterWindow::wxThinSplitterWindow(wxWindow* parent, wxWindowID id,
518
                                           const wxPoint& pos,
519
                                           const wxSize& sz,
520
                                           long style):
521
wxSplitterWindow(parent, id, pos, sz, style)
522
{
523
}
524
 
525
void wxThinSplitterWindow::SizeWindows()
526
{
527
    // The client size may have changed inbetween
528
    // the sizing of the first window and the sizing of
529
    // the second. So repeat SizeWindows.
530
    wxSplitterWindow::SizeWindows();
531
    wxSplitterWindow::SizeWindows();
532
}
533
 
534
// Tests for x, y over sash
535
bool wxThinSplitterWindow::SashHitTest(int x, int y, int tolerance)
536
{
537
    return wxSplitterWindow::SashHitTest(x, y, 4);
538
}
539
 
540
void wxThinSplitterWindow::DrawSash(wxDC& dc)
541
{
542
    if ( m_sashPosition == 0 || !m_windowTwo)
543
        return;
544
    if (GetWindowStyle() & wxSP_NOSASH)
545
        return;
546
 
547
    int w, h;
548
    GetClientSize(&w, &h);
549
 
550
    if ( m_splitMode == wxSPLIT_VERTICAL )
551
    {
552
#if wxCHECK_VERSION(2, 6, 0)
553
                // The variables below don't seem to exist....
554
                wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
555
                dc.SetPen(pen);
556
                dc.SetBrush(* wxTRANSPARENT_BRUSH);
557
#else
558
        dc.SetPen(* m_facePen);
559
        dc.SetBrush(* m_faceBrush);
560
#endif
561
        int h1 = h-1;
562
        int y1 = 0;
563
        if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER )
564
            h1 += 1; // Not sure why this is necessary...
565
        if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER)
566
        {
567
            y1 = 2; h1 -= 3;
568
        }
569
        dc.DrawRectangle(m_sashPosition, y1, m_sashSize, h1);
570
    }
571
    else
572
    {
573
#if wxCHECK_VERSION(2, 6, 0)
574
                // The variables below don't seem to exist....
575
                wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
576
                dc.SetPen(pen);
577
                dc.SetBrush(* wxTRANSPARENT_BRUSH);
578
#else
579
        dc.SetPen(* m_facePen);
580
        dc.SetBrush(* m_faceBrush);
581
#endif
582
        int w1 = w-1;
583
        int x1 = 0;
584
        if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER )
585
            w1 ++;
586
        if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER)
587
        {
588
            x1 = 2; w1 -= 3;
589
        }
590
        dc.DrawRectangle(x1, m_sashPosition, w1, m_sashSize);
591
    }
592
 
593
    dc.SetPen(wxNullPen);
594
    dc.SetBrush(wxNullBrush);
595
}
596
 
597
void wxThinSplitterWindow::OnSize(wxSizeEvent& event)
598
{
599
    wxSplitterWindow::OnSize(event);
600
}
601
 
602
/*
603
* wxSplitterScrolledWindow
604
*/
605
 
606
IMPLEMENT_CLASS(wxSplitterScrolledWindow, ecScrolledWindow)
607
 
608
BEGIN_EVENT_TABLE(wxSplitterScrolledWindow, ecScrolledWindow)
609
EVT_SCROLLWIN(wxSplitterScrolledWindow::OnScroll)
610
EVT_SIZE(wxSplitterScrolledWindow::OnSize)
611
END_EVENT_TABLE()
612
 
613
wxSplitterScrolledWindow::wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id,
614
                                                   const wxPoint& pos,
615
                                                   const wxSize& sz,
616
                                                   long style):
617
  ecScrolledWindow(parent, id, pos, sz, style)
618
{
619
}
620
 
621
void wxSplitterScrolledWindow::OnSize(wxSizeEvent& event)
622
{
623
    wxSize sz = GetClientSize();
624
#if wxCHECK_VERSION(2, 6, 0)
625
    if (GetChildren().GetFirst())
626
    {
627
        ((wxWindow*) GetChildren().GetFirst()->GetData())->SetSize(0, 0, sz.x, sz.y);
628
#else
629
    if (GetChildren().First())
630
    {
631
        ((wxWindow*) GetChildren().First()->Data())->SetSize(0, 0, sz.x, sz.y);
632
#endif
633
    }
634
}
635
 
636
void wxSplitterScrolledWindow::OnScroll(wxScrollWinEvent& event)
637
{
638
    // Ensure that events being propagated back up the window hierarchy
639
    // don't cause an infinite loop
640
    static bool inOnScroll = FALSE;
641
    if (inOnScroll)
642
    {
643
        event.Skip();
644
        return;
645
    }
646
    inOnScroll = TRUE;
647
 
648
    int orient = event.GetOrientation();
649
 
650
    int nScrollInc = CalcScrollInc(event);
651
    if (nScrollInc == 0)
652
    {
653
        inOnScroll = FALSE;
654
        return;
655
    }
656
 
657
    if (orient == wxHORIZONTAL)
658
    {
659
        inOnScroll = FALSE;
660
        event.Skip();
661
        return;
662
#if 0
663
        int newPos = m_xScrollPosition + nScrollInc;
664
        SetScrollPos(wxHORIZONTAL, newPos, TRUE );
665
#endif
666
    }
667
    else
668
    {
669
        int newPos = m_yScrollPosition + nScrollInc;
670
        SetScrollPos(wxVERTICAL, newPos, TRUE );
671
    }
672
 
673
    if (orient == wxHORIZONTAL)
674
    {
675
        m_xScrollPosition += nScrollInc;
676
    }
677
    else
678
    {
679
        m_yScrollPosition += nScrollInc;
680
    }
681
 
682
    // Find targets in splitter window and send the event to them
683
 
684
#if wxCHECK_VERSION(2, 6, 0)
685
    wxNode* node = (wxNode *) GetChildren().GetFirst();
686
    while (node)
687
    {
688
        wxWindow* child = (wxWindow*) node->GetData();
689
#else
690
    wxNode* node = GetChildren().First();
691
    while (node)
692
    {
693
        wxWindow* child = (wxWindow*) node->Data();
694
#endif
695
        if (child->IsKindOf(CLASSINFO(wxSplitterWindow)))
696
        {
697
            wxSplitterWindow* splitter = (wxSplitterWindow*) child;
698
            if (splitter->GetWindow1())
699
                splitter->GetWindow1()->ProcessEvent(event);
700
            if (splitter->GetWindow2())
701
                splitter->GetWindow2()->ProcessEvent(event);
702
            break;
703
        }
704
#if wxCHECK_VERSION(2, 6, 0)
705
        node = node->GetNext();
706
#else
707
        node = node->Next();
708
#endif
709
    }
710
 
711
#ifdef __WXMAC__
712
    m_targetWindow->MacUpdateImmediately() ;
713
#endif
714
 
715
    inOnScroll = FALSE;
716
}
717
 

powered by: WebSVN 2.1.0

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