-
Notifications
You must be signed in to change notification settings - Fork 0
/
wxFreeSplitter.cpp
1014 lines (822 loc) · 28.3 KB
/
wxFreeSplitter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************
* Name: wxFreeSplitter.cpp
* Purpose: wxFreeStyleSizer class interface
* Author: Sergey Dvoryantsev
* Created: 2019-09-19
* Copyright: (c) Sergey Dvoryantsev
* License:
**************************************************************/
#include "wx/dcmirror.h"
#include "wx/dcmirror.h"
#include "wx/renderer.h"
#include "wx/dcbuffer.h"
#include "wxFreeSplitter.h"
#include "wxFreeStyleSizer.h"
wxIMPLEMENT_DYNAMIC_CLASS(wxFreeSplitter, wxWindow);
wxBEGIN_EVENT_TABLE(wxFreeSplitter, wxWindow)
EVT_PAINT(wxFreeSplitter::OnPaint)
EVT_SIZE(wxFreeSplitter::OnSize)
EVT_MOUSE_EVENTS(wxFreeSplitter::OnMouseEvent)
EVT_MOUSE_CAPTURE_LOST(wxFreeSplitter::OnMouseCaptureLost)
//EVT_ENTER_WINDOW()
//EVT_LEAVE_WINDOW()
//#if defined( __WXMSW__ ) || defined( __WXMAC__)
// EVT_SET_CURSOR(wxFreeSplitter::OnSetCursor)
//#endif // wxMSW
wxEND_EVENT_TABLE()
// -----------------------------------------------------------------------------
// wxFreeSplitter
// -----------------------------------------------------------------------------
wxFreeSplitter::wxFreeSplitter()
{
Init();
}
wxFreeSplitter::wxFreeSplitter(wxFreeSizerItem * owner_, wxSplitSide side_)
{
Init();
SetOwner(owner_, side_);
}
wxFreeSplitter::~wxFreeSplitter()
{
m_penBtnHLG.FreeResource();
m_penBtnSHD.FreeResource();
m_penDarkGrey.FreeResource();
m_penLightGrey.FreeResource();
m_penHighLight.FreeResource();
}
void wxFreeSplitter::AssignOwner(wxFreeSizerItem * owner_, wxSplitSide side_)
{
SetOwner(owner_, side_);
}
void wxFreeSplitter::SetOwner(wxFreeSizerItem * owner_, wxSplitSide side_)
{
m_owner = owner_;
m_splitSide = side_;
SetSplitPanelSize(-1);
if (IsOwned()) {
SetSplitPanelSize(m_owner->GetBorder() - 1);
doArrangeByOwner();
}
}
bool wxFreeSplitter::Show()
{
if (IsOwned()) {
/*if ( !m_hWnd ) */ {
wxWindow * parentWindow = GetParentWindow();
long style = wxTAB_TRAVERSAL | wxBORDER_NONE;// | wxFULL_REPAINT_ON_RESIZE ; //wxSIMPLE_BORDER;//wxSUNKEN_BORDER;
doArrangeByOwner();
if ( wxWindow::Create(parentWindow, wxID_ANY, m_curPosition, m_curSize, style, "wxFreeSplitter") ) {
#if !defined(__WXGTK__) || defined(__WXGTK20__)
// don't erase the splitter background, it's pointless as we overwrite it
// anyhow
SetBackgroundStyle(wxBG_STYLE_PAINT);
#endif
#ifdef TEST_COLOR
Test_ColoredSplitters();
#endif
return true;
}
}
return wxWindow::Show();
}
return false;
}
void wxFreeSplitter::Hide()
{
//wxWindow::Hide();
}
bool wxFreeSplitter::IsVisible()
{
return wxWindow::IsShown();
}
// (***
void wxFreeSplitter::SetPosition(const wxPoint & pos_)
{
// is position not changed
//if ( m_curPosition == pos_ ) return;
// calculate real position and apply it to Window
// Note:
// don't call wxWindow::SetPosition
// instead use doSetWindowPosition
//doSetWindowPosition(pos_);
m_curPosition = pos_;
wxWindow::SetPosition(m_curPosition);
}
void wxFreeSplitter::SetSize(const wxSize & sz_)
{
// is size not changed
// if ( m_curSize == sz_ ) return;
// calculate size by it constraint
m_curSize = AdjustSize(sz_);
// actual position apply to Window
wxWindow::SetSize(m_curSize);
// doSetWindowSize(sz_);
}
void wxFreeSplitter::ArrangeByOwner()
{
if ( !IsOwned() ) return;
doArrangeByOwner();
}
bool wxFreeSplitter::doArrangeByOwner()
{
if (IsOwned() == false) return false;
if ( IsDragging()) return false;
// must be the FIRST
SetSize( CalcSizeByOwner() );
// must be the SECOND
SetPosition( CalcPosByOwner() );
//Refresh(false);
Refresh(true);
//Update();
return true;
}
wxPoint wxFreeSplitter::CalcPosByOwner()
{
if ( !IsOwned() ) return GetCurPosition();
wxRect rectOwner( GetOwnerWindow()->GetPosition(), GetOwnerWindow()->GetSize() );
wxPoint pos;
switch (GetSplitSide()) {
case wxRS_TOP: pos = rectOwner.GetLeftTop();
break;
case wxRS_LEFT: pos = rectOwner.GetLeftTop();
break;
case wxRS_RIGHT: pos = rectOwner.GetTopRight();
break;
case wxRS_BOTTOM: pos = rectOwner.GetBottomLeft();
break;
}
return CorrPosByOwnerAngle(pos);
}
// correction position by owner angle
wxPoint wxFreeSplitter::CorrPosByOwnerAngle(const wxPoint & ownpos_)
{
wxPoint pos(ownpos_);
switch (GetSplitSide()) {
case wxRS_TOP: pos.y -= m_curSize.y; break; // shift above owner
case wxRS_LEFT: pos.x -= m_curSize.x; break; // shift before left of the owner
case wxRS_RIGHT: pos.x += 1; break; // shift after right of the owner
case wxRS_BOTTOM: pos.y += 1; break; // shift under owner
}
return pos;
}
wxSize wxFreeSplitter::CalcSizeByOwner()
{
if ( !IsOwned() ) return GetCurSize();
//int sz_splitter = m_splitPanelSize;
//int sz_border = GetOwner()->GetBorder();
wxSize sz_owner = GetOwner()->GetFrameSize();
wxSize sz;
SetSplitPanelSize(GetOwner()->GetBorder());// - 1);
switch (GetSplitSide()) {
case wxRS_TOP: sz = wxSize( sz_owner.x, m_splitPanelSize );
break;
case wxRS_LEFT: sz = wxSize( m_splitPanelSize, sz_owner.y/* - sz_border*/ );
break;
case wxRS_RIGHT: sz = wxSize( m_splitPanelSize, sz_owner.y/* - sz_border*/ );
break;
case wxRS_BOTTOM: sz = wxSize( sz_owner.x, m_splitPanelSize );
break;
}
return AdjustSize(sz);
}
void wxFreeSplitter::UpdateOwnerPosition( int dx_, int dy_ )
{
if (!IsOwned()) return;
doUpdateOwnerPosition( dx_, dy_ );
}
void wxFreeSplitter::doUpdateOwnerPosition( int dx_, int dy_ )
{
if ( IsOwned() ) {
// shift owner position and size
// GetOwner()->ShiftSide( GetSplitSide(), dx_, dy_ );
if ( IsSplitVertical() )
GetOwner()->ShiftSide( GetSplitSide(), dx_, 0 );
else GetOwner()->ShiftSide( GetSplitSide(), 0, dy_ );
// callback update to parent sizer
GetOwner()->Callback_OwnerLayout();
}
}
void wxFreeSplitter::Init()
{
m_owner = NULL;
m_Dragging = false;
m_trackerVisible = false;
m_splitSide = wxRS_NO;
m_trackerStyle = def_trackerStyle;
m_splitterStyle = def_splitterStyle;
m_splitPanelSize = def_splitPanelSize;
m_trackLineSize = def_trackLineSize;
m_cursorResizeV = wxCursor( wxCURSOR_SIZEWE );
m_cursorResizeH = wxCursor( wxCURSOR_SIZENS );
m_trackerPattern = CreatePatternBitmap( *wxWHITE, *wxBLACK );
m_dragMouseStart = wxPoint();
m_dragPosStart = wxPoint();
m_dragPosCurrent = wxPoint();
m_curPosition; // current window position
m_curSize;
// paint resources
m_penBtnHLG = wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNHIGHLIGHT ));
m_penBtnSHD = wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ));
m_penDarkGrey = wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_3DSHADOW ));
m_penLightGrey = wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ));
m_penHighLight = wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_3DHIGHLIGHT ));
}
wxSize wxFreeSplitter::AdjustSize( const wxSize & sz_ )
{
wxSize sz_res( sz_ );
if ( IsSplitVertical() ) {
// splitter width can't be less def_splitPanelSize
if ( sz_res.x < def_splitPanelSize )
sz_res.x = def_splitPanelSize;
// splitter height can't be less 0
if ( sz_res.y < 0 )
sz_res.y = 0;
} else {
// splitter height can't be less def_splitPanelSize
if ( sz_res.y < def_splitPanelSize )
sz_res.y = def_splitPanelSize;
// splitter width can't be less 0
if ( sz_res.x < 0 )
sz_res.x = 0;
}
return sz_res;
}
inline
bool wxFreeSplitter::IsOwned()
{
return m_owner && m_owner->IsWindow();
}
inline
wxFreeSizerItem * wxFreeSplitter::GetOwner()
{
return m_owner;
}
inline
wxWindow * wxFreeSplitter::GetOwnerWindow()
{
return ( m_owner ? m_owner->GetWindow()
: NULL );
}
inline
wxWindow * wxFreeSplitter::GetParentWindow()
{
return ( IsOwned() ? GetOwnerWindow()->GetParent()
: NULL );
}
void wxFreeSplitter::SetTrackerStyle( wxTrackerStyle st_ )
{
m_trackerStyle = st_;
}
void wxFreeSplitter::SetSplitterStyle( wxSplitterStyle st_ )
{
m_splitterStyle = st_;
}
void wxFreeSplitter::SetSplitPanelSize( int sz_ )
{
m_splitPanelSize = ( sz_ >= 0 ) ? sz_ : def_splitPanelSize;
}
void wxFreeSplitter::SetSplitTrackerSize( int sz_ )
{
m_trackLineSize = ( sz_ >= 0 ) ? sz_ : def_trackLineSize;
}
// Events
void wxFreeSplitter::OnEnterSplitter()
{
doSelectResizeCursor();
}
void wxFreeSplitter::OnLeaveSplitter()
{
SetCursor( *wxSTANDARD_CURSOR );
}
void wxFreeSplitter::doSelectResizeCursor()
{
SetCursor( IsSplitVertical() ? m_cursorResizeV
: m_cursorResizeH );
}
wxSplitterStyle wxFreeSplitter::GetAutoSplitterStyle()
{
wxSplitterStyle spstyle = GetSplitterStyle();
if ( spstyle == wxSS_AUTO && IsOwned() ) {
wxWindow * win = GetOwner()->GetWindow();
spstyle = wxSplitterStyle::wxSS_PATTERN;
if ( win ) {
switch ( win->GetBorder() ) {
case wxBORDER_DEFAULT: // 0
spstyle = wxSplitterStyle::wxSS_BEVEL;
break;
case wxBORDER_NONE: // 0x00200000
spstyle = wxSplitterStyle::wxSS_BEVEL;
break;
case wxBORDER_STATIC: // 0x01000000
spstyle = wxSplitterStyle::wxSS_PATTERN;
break;
case wxBORDER_SIMPLE: // 0x02000000
spstyle = wxSplitterStyle::wxSS_PATTERN;
break;
case wxBORDER_RAISED: // 0x04000000
spstyle = wxSplitterStyle::wsSS_FRAME_3DRAISED;
break;
case wxBORDER_SUNKEN: // 0x08000000
spstyle = wxSplitterStyle::wsSS_FRAME_3DSUNKEN;
break;
//case wxBORDER::wxBORDER_DOUBLE: // 0x10000000 /* deprecated */
case wxBORDER_THEME: // wxBORDER_DOUBLE,
spstyle = wxSplitterStyle::wxSS_PATTERN;
break;
}
}
}
return spstyle;
}
void wxFreeSplitter::OnPaint( wxPaintEvent& event )
{
if ( IsVisible() == false ) return;
// draw splitter panel
wxPaintDC dc( this );
//wxBufferedPaintDC dc( this );
wxRect rect = GetClientRect();
//wxSplitterStyle spl_style = GetSplitterStyle();
#ifdef __WXOSX__
// as subpanels might have a transparent background we must erase the background
// at least on OSX, otherwise traces of the sash will remain
// test with: splitter sample->replace right window
dc.Clear();
#endif
//dc.Clear();
switch ( GetAutoSplitterStyle() ) {
case wxSS_PATTERN: doDrawSplitter_Pattern(dc, rect);
break;
case wxSS_PATTERN_TR: doDrawSplitter_Pattern(dc, rect, true);
break;
case wxSS_BEVEL: doDrawSplitter_Bevel(dc, rect);
break;
case wxSS_BEVEL_TR: doDrawSplitter_Bevel(dc, rect, true);
break;
case wsSS_FRAME_3DRAISED: doDrawSplitter_Frame_3DRaised(dc, rect);
break;
case wsSS_FRAME_3DSUNKEN: doDrawSplitter_Frame_3DSunken(dc, rect);
break;
}
}
// draw splitters
void wxFreeSplitter::doDrawSplitter_Pattern(wxDC & dc_, wxRect & rect_, bool tr_)
{
wxBrush brush;
brush.SetColour(GetBackgroundColour());
brush.SetStyle(wxBRUSHSTYLE_SOLID);
// is transparent
if (tr_)
dc_.SetBrush(*wxTRANSPARENT_BRUSH);
else dc_.SetBrush(brush);
dc_.SetPen(*wxTRANSPARENT_PEN);
dc_.DrawRectangle(rect_);
dc_.SetPen(wxNullPen);
dc_.SetBrush(wxNullBrush);
brush.FreeResource();
}
void wxFreeSplitter::doDrawSplitter_Bevel( wxDC & dc_, wxRect & rect_, bool tr_ )
{
//wxPen pen_lh( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNHIGHLIGHT ) );
//wxPen pen_sh( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) );
wxPen pen_bg( GetBackgroundColour() );
wxBrush brush;
wxRect rc(rect_);
//brush.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DSHADOW ) ); // test
brush.SetColour( GetBackgroundColour() );
brush.SetStyle( wxBRUSHSTYLE_SOLID );
// pre-set rect
if ( IsSplitVertical() )
rc.Inflate( 0, 1 );
else rc.Inflate( 1, 0 );
// is not transparent - clear background
if (tr_ == false) {
dc_.SetBrush( brush );
dc_.DrawRectangle( rc );
}
// continue with transparent brush
dc_.SetBrush( *wxTRANSPARENT_BRUSH );
// 1 rect
//rc.Inflate( -1, -1 );
rc.Inflate( -2, -2 );
doDrawRoundedRectangle( dc_, rc, m_penBtnHLG, m_penBtnSHD );
// 2 rect
rc.Inflate( 1, 1 );
doDrawRoundedRectangle( dc_, rc, m_penBtnSHD, pen_bg );
// 3 rect clear external border area
rc.Inflate( 1, 1 );
doDrawRoundedRectangle( dc_, rc, pen_bg, pen_bg );
dc_.SetPen( wxNullPen );
dc_.SetBrush( wxNullBrush );
//pen_lh.FreeResource();
//pen_sh.FreeResource();
pen_bg.FreeResource();
brush.FreeResource();
}
void wxFreeSplitter::doDrawRoundedRectangle( wxDC & dc_, wxRect & rect_, wxPen & penrc_, wxPen & penbg_ )
{
wxRect rcpick = rect_;
rcpick.Inflate(-1, -1);
dc_.SetPen( penrc_ );
dc_.DrawRectangle( rect_ );
// pick colored points in rectangle ( wall -1 )
dc_.DrawPoint( rcpick.GetLeftTop() );
dc_.DrawPoint( rcpick.GetLeftBottom() );
dc_.DrawPoint( rcpick.GetRightTop() );
dc_.DrawPoint( rcpick.GetRightBottom() );
// unpick colored points in rectangle wall
dc_.SetPen( penbg_ );
dc_.DrawPoint( rect_.GetLeftTop() );
dc_.DrawPoint( rect_.GetLeftBottom() );
dc_.DrawPoint( rect_.GetRightTop() );
dc_.DrawPoint( rect_.GetRightBottom() );
}
void wxFreeSplitter::doDrawSplitter_Frame_3DRaised(wxDC & dc_, wxRect & rect_)
{
// pre-set rect
if ( IsSplitVertical() )
rect_.Inflate( 0, 1 );
else rect_.Inflate( 1, 0 );
dc_.SetBrush(*wxTRANSPARENT_BRUSH);
rect_.Offset(-1, -1);
dc_.SetPen(m_penDarkGrey);
dc_.DrawRectangle(rect_);
rect_.Offset (2, 2);
dc_.SetPen(m_penHighLight);
dc_.DrawRectangle(rect_);
rect_.Offset (-1, -1);
dc_.SetPen(m_penLightGrey);
dc_.DrawRectangle(rect_);
dc_.SetPen(wxNullPen);
dc_.SetBrush(wxNullBrush);
}
void wxFreeSplitter::doDrawSplitter_Frame_3DSunken(wxDC & dc_, wxRect & rect_)
{
// pre-set rect
if ( IsSplitVertical() )
rect_.Inflate( 0, 1 );
else rect_.Inflate( 1, 0 );
dc_.SetBrush(*wxTRANSPARENT_BRUSH);
rect_.Offset(-1, -1);
dc_.SetPen(m_penHighLight);
dc_.DrawRectangle(rect_);
rect_.Offset (2, 2);
dc_.SetPen(m_penDarkGrey);
dc_.DrawRectangle(rect_);
rect_.Offset (-1, -1);
dc_.SetPen(m_penLightGrey);
dc_.DrawRectangle(rect_);
dc_.SetPen(wxNullPen);
dc_.SetBrush(wxNullBrush);
}
// do dragging
void wxFreeSplitter::doBeginDrag()
{
m_Dragging = true;
// hide/show splitter only if wxST_UPDATE
if ( m_trackerStyle == wxST_UPDATE ) {
m_lastStateVisible = IsVisible();
if ( IsVisible() ) wxWindow::Hide();
}
}
void wxFreeSplitter::doEndDrag()
{
m_Dragging = false;
// live update
if ( m_trackerStyle == wxST_UPDATE ) {
if ( !IsVisible() && m_lastStateVisible ) wxWindow::Show();
}
}
/*
void wxFreeSplitter::doDrawRefreshRectangle( int x_, int y_ )
{
wxWindow * parentWindow = GetParent();
if ( parentWindow ) {
wxPoint trcPos( x_, y_ );
wxSize trcSize( GetSize() ); // for begin = splitter size
// set tracker size
if ( IsSplitVertical() )
trcSize.x = m_trackLineSize;
else trcSize.y = m_trackLineSize;
{
wxRect rc( trcPos, trcSize );
parentWindow->Refresh( true, &rc );
}
}
}
*/
int wxFreeSplitter::CalcConstraintDrag_X( int dx_ )
{
wxWindow * parentWindow = GetParent();
int diff_x = dx_;
// constraint min/max dragging position
if ( parentWindow && m_owner ) {
int minPosX, maxPosX, posX;
minPosX = 0;
maxPosX = parentWindow->GetSize().x; // GetPosition().x + GetSize().x;
posX = m_dragPosStart.x + dx_;
switch ( GetSplitSide() ) {
case wxRS_LEFT: maxPosX = m_owner->GetPosition().x + m_owner->GetSize().x;
break;
case wxRS_RIGHT: minPosX = m_owner->GetPosition().x;
break;
}
// drag tracker must between minPos and maxPos
posX = wxClip( posX, minPosX, maxPosX );
diff_x = posX - m_dragPosStart.x;
}
return diff_x;
}
int wxFreeSplitter::CalcConstraintDrag_Y( int dy_ )
{
wxWindow * parentWindow = GetParent();
int diff_y = dy_;
// constraint min/max dragging position
if ( parentWindow && m_owner ) {
int minPosY, maxPosY, posY;
minPosY = 0;
maxPosY = parentWindow->GetSize().y; // GetPosition().x + GetSize().x;
posY = m_dragPosStart.y + dy_;
switch ( GetSplitSide() ) {
case wxRS_TOP: maxPosY = m_owner->GetPosition().y + m_owner->GetSize().y;
break;
case wxRS_BOTTOM: minPosY = m_owner->GetPosition().y;
break;
}
// drag tracker must between minPos and maxPos
posY = wxClip( posY, minPosY, maxPosY );
diff_y = posY - m_dragPosStart.y;
}
return diff_y;
}
/*
wxPoint wxFreeSplitter::CalcDragConstraint( const wxPoint & pos_ )
{
wxPoint pos(pos_);
wxWindow * parentWindow = GetParent();
// constraint min/max dragging position
if ( parentWindow && m_owner ) {
int minPosX, maxPosX, minPosY, maxPosY;
minPosX = 0;
minPosY = 0;
maxPosX = parentWindow->GetSize().x; // GetPosition().x + GetSize().x;
maxPosY = parentWindow->GetSize().y; // GetPosition().y + GetSize().y;
switch ( GetSplitSide() ) {
case wxRS_LEFT: maxPosX = m_owner->GetPosition().x + m_owner->GetSize().x;
break;
case wxRS_RIGHT: minPosX = m_owner->GetPosition().x;
break;
case wxRS_TOP: maxPosY = m_owner->GetPosition().y + m_owner->GetSize().y;
break;
case wxRS_BOTTOM: minPosY = m_owner->GetPosition().y;
break;
}
// drag tracker must between minPos and maxPos
pos.x = wxClip( pos.x, minPosX, maxPosX );
pos.y = wxClip( pos.y, minPosY, maxPosY );
}
m_dragPosStart
return pos;
}
*/
// window events handling
void wxFreeSplitter::OnMouseEvent( wxMouseEvent& event_ )
{
wxPoint ptMouseCurrent = event_.GetPosition();
if ( event_.LeftDown() ) {
CaptureMouse();
// set cursor
doSelectResizeCursor();
m_dragMouseStart = ptMouseCurrent;
m_dragPosStart = GetPosition();
m_dragPosCurrent = m_dragPosStart;
// do begin drag now
doBeginDrag();
return;
} else
if ( event_.LeftUp() ) {
if ( IsDragging() ) {
int diffX = ptMouseCurrent.x - m_dragMouseStart.x;
int diffY = ptMouseCurrent.y - m_dragMouseStart.y;
if (IsSplitVertical())
diffY = 0;
else diffX = 0;
// do end drag
doEndDrag();
// Release mouse and unset the cursor
ReleaseMouse();
SetCursor( * wxSTANDARD_CURSOR );
// Erase old tracker
if ( m_trackerStyle != wxST_UPDATE ) {
if ( m_trackerVisible )
DrawSplitTracker( m_dragPosCurrent.x, m_dragPosCurrent.y );
m_trackerVisible = false;
}
// live update owner position
UpdateOwnerPosition( CalcConstraintDrag_X( diffX ),
CalcConstraintDrag_Y( diffY ) );
}
} else
if ( event_.Moving() || event_.Leaving() || event_.Entering() ) {
if ( IsDragging() == false ) {
if ( event_.Leaving() )
OnLeaveSplitter();
else OnEnterSplitter();
}
} else
if ( event_.Dragging()) {
if ( IsDragging() ) {
wxWindow * parentWindow = GetParent();
wxPoint ptNewPos;
int diffX = ptMouseCurrent.x - m_dragMouseStart.x;
int diffY = ptMouseCurrent.y - m_dragMouseStart.y;
// nothing to drag
if ( !diffX && !diffY ) return;
// add offset V or H position only
ptNewPos = m_dragPosStart;
if ( IsSplitVertical() ) {
diffY = 0;
ptNewPos.x += CalcConstraintDrag_X( diffX );
} else {
diffX = 0;
ptNewPos.y += CalcConstraintDrag_Y( diffY );
}
// constraint min/max dragging position
//ptNewPos = CalcDragConstraint( ptNewPos );
// do tracker show
if (m_trackerStyle != wxST_UPDATE) {
// erase old tracker
if ( m_trackerVisible ) {
DrawSplitTracker( m_dragPosCurrent.x, m_dragPosCurrent.y );
//doDrawRefreshRectangle( m_dragPosCurrent.x, m_dragPosCurrent.y );
}
// draw new tracker
DrawSplitTracker( ptNewPos.x, ptNewPos.y );
m_trackerVisible = true;
m_dragPosCurrent = ptNewPos;
}
else {
// live update owner position
UpdateOwnerPosition(diffX, diffY);
// in live mode, the new position is the actual sash position, clear requested position!
m_dragMouseStart = ptMouseCurrent;
m_dragPosStart = ptNewPos;
m_dragPosCurrent = ptNewPos;
//wxWindow::Move( GetOwner()->GetRect().GetRightTop() );
}
}
//} else
//if ( event_.LeftDClick() && m_windowTwo ) {
// OnDoubleClickSash(x, y);
} else {
event_.Skip();
}
}
// Draw the sash tracker (for whilst moving the sash)
void wxFreeSplitter::DrawSplitTracker(int x_, int y_)
{
wxWindow * parentWindow = GetParent();
if (parentWindow) {
wxPoint trcPos( x_, y_ );
wxSize trcSize( GetSize() ); // for begin = splitter size
// set tracker size
if (IsSplitVertical())
trcSize.x = m_trackLineSize; //szSplitter.y;
else trcSize.y = m_trackLineSize; //szSplitter.x;
switch (m_trackerStyle) {
// tracker line mode
case wxST_LINE: doDrawTrackerLineMSW(trcPos, trcSize);
break;
// tracker pattern mode
case wxST_PATTERN: doDrawTrackerPatternMSW(trcPos, trcSize);
//doDrawTrackerPattern(pos, sz);
break;
default: break;
}
}
return;
}
// (!) Line not drawing top above panels
void wxFreeSplitter::doDrawTrackerLine(const wxPoint & pos_, const wxSize & size_)
{
wxWindow * parentWindow = GetParent();
if (parentWindow == NULL) {
// assert
return;
}
wxBrush brush(m_trackerPattern);
wxClientDC clientDC(parentWindow);
// line 1 : DrawLine
//clientDC.SetLogicalFunction(wxINVERT);
//clientDC.SetPen(*m_sashTrackerPen);
//clientDC.SetBrush(*wxTRANSPARENT_BRUSH);
//clientDC.DrawLine(x1, y1, x2, y2); // DrawRectangle !!! Size as Splitter
//clientDC.SetLogicalFunction(wxCOPY);
// line 2 : DrawRectangle
clientDC.SetPen(*wxTRANSPARENT_PEN);
clientDC.SetBrush(*wxWHITE_BRUSH);
clientDC.SetLogicalFunction(wxINVERT);
clientDC.DrawRectangle(pos_, size_);//rect_.x, rect_.y, rect_.width, rect_.height);
clientDC.SetLogicalFunction(wxCOPY);
clientDC.SetPen(wxNullPen);
clientDC.SetBrush(wxNullBrush);
}
// (!) Line not drawing top above panels
void wxFreeSplitter::doDrawTrackerLineMSW(const wxPoint & pos_, const wxSize & size_)
{
wxWindow * parentWindow = GetParent();
if (parentWindow == NULL) {
// assert
return;
}
// MSW
HWND hWnd = parentWindow->GetHWND();
HDC hDC = GetDCEx(hWnd, NULL, DCX_CACHE | DCX_CLIPSIBLINGS | DCX_LOCKWINDOWUPDATE);
PatBlt(hDC, pos_.x, pos_.y, size_.x, size_.y, PATINVERT);
ReleaseDC(hWnd, hDC);
}
void wxFreeSplitter::doDrawTrackerPattern(const wxPoint & pos_, const wxSize & size_)
{
wxWindow * parentWindow = GetParent();
if (parentWindow == NULL) {
// assert
return;
}
wxBrush brush(m_trackerPattern);
wxClientDC clientDC(parentWindow);
clientDC.SetPen(*wxTRANSPARENT_PEN);
clientDC.SetBrush(brush);
clientDC.SetLogicalFunction(wxXOR);
clientDC.DrawRectangle(pos_, size_);
clientDC.SetLogicalFunction(wxCOPY);
clientDC.SetPen(wxNullPen);
clientDC.SetBrush(wxNullBrush);
}
void wxFreeSplitter::doDrawTrackerPatternMSW(const wxPoint & pos_, const wxSize & size_)
{
wxWindow * parentWindow = GetParent();
if (parentWindow == NULL) {
// assert
return;
}
// GetDCEx() must give possible paint over all child windows
// We not use wxClientDC - has artefacts, desktop background on repaint and
// Win7/10 scalling factor ( 125, 150, 175% ) tracking position problem.
// Windows GDI paint level
HWND hWnd = parentWindow->GetHWND();
HDC hDC = GetDCEx(hWnd, NULL, DCX_CACHE | DCX_CLIPSIBLINGS | DCX_LOCKWINDOWUPDATE);
HBRUSH hBrush = CreatePatternBrush(m_trackerPattern.GetHBITMAP());
HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);
PatBlt(hDC, pos_.x, pos_.y, size_.x, size_.y, PATINVERT);
SelectObject(hDC, hOldBrush);
DeleteObject(hBrush);
ReleaseDC(hWnd, hDC);
}
wxBitmap wxFreeSplitter::CreatePatternBitmap(wxColor bgcolor_, wxColor fgcolor_)
{
wxBitmap bmp(8, 8, -1);
wxMemoryDC dc;
wxBrush brush;
wxPen pen;
brush.SetStyle(wxBRUSHSTYLE_SOLID);
brush.SetColour(bgcolor_);
pen.SetStyle(wxPENSTYLE_SOLID);
pen.SetColour(fgcolor_);
dc.SelectObject(bmp);
dc.SetBrush(brush);
dc.SetPen(pen);
dc.Clear();
for (int iy = 0; iy <= dc.GetSize().y; iy++)
for (int ix = 0; ix <= dc.GetSize().x; ix++ )
if ( ix % 2 == iy % 2)
dc.DrawPoint(ix, iy);
dc.SelectObject(wxNullBitmap);
return bmp;
}
double wxFreeSplitter::GetScalingFactor()
{
return 1;
}
// this is currently called (and needed) under MSW only...
void wxFreeSplitter::OnSetCursor(wxSetCursorEvent& event)
{
event.Skip();
}
#ifdef TEST_COLOR
void wxFreeSplitter::Test_ColoredSplitters()
{
switch(m_splitSide) {
case wxRS_TOP:
SetBackgroundColour(wxColour(* wxBLUE));