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