]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/fl/bardragpl.cpp
Added window styles to wxToolBar handler.
[wxWidgets.git] / contrib / src / fl / bardragpl.cpp
CommitLineData
8e08b761 1/////////////////////////////////////////////////////////////////////////////
4cbc57f0
JS
2// Name: bardragpl.cpp
3// Purpose: cbBarDragPlugin implementation
8e08b761
JS
4// Author: Aleksandras Gluchovas
5// Modified by:
6// Created: 23/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Aleksandras Gluchovas
4cbc57f0 9// Licence: wxWindows licence
8e08b761
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13 #pragma implementation "bardragpl.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/wx.h"
25#endif
26
27#include "wx/fl/bardragpl.h"
28
29#define POS_UNDEFINED -32768
30
31// helpers, FOR NOW:: static
32
33static inline bool rect_hits_rect( const wxRect& r1, const wxRect& r2 )
34{
35 if ( ( r2.x >= r1.x && r2.x <= r1.x + r1.width ) ||
36 ( r1.x >= r2.x && r1.x <= r2.x + r2.width ) )
37
38 if ( ( r2.y >= r1.y && r2.y <= r1.y + r1.height ) ||
39 ( r1.y >= r2.y && r1.y <= r2.y + r2.height ) )
40
41 return TRUE;
42
43 return FALSE;
44}
45
46static inline bool rect_contains_point( const wxRect& rect, int x, int y )
47{
48 return ( x >= rect.x &&
49 y >= rect.y &&
50 x < rect.x + rect.width &&
51 y < rect.y + rect.height );
52}
53
54/***** Implementation for class cbBarDragPlugin *****/
55
56IMPLEMENT_DYNAMIC_CLASS( cbBarDragPlugin, cbPluginBase )
57
58BEGIN_EVENT_TABLE( cbBarDragPlugin, cbPluginBase )
59
60 //EVT_PL_LEFT_DOWN ( cbBarDragPlugin::OnLButtonDown )
61 EVT_PL_LEFT_UP ( cbBarDragPlugin::OnLButtonUp )
62 EVT_PL_MOTION ( cbBarDragPlugin::OnMouseMove )
63 EVT_PL_DRAW_HINT_RECT ( cbBarDragPlugin::OnDrawHintRect )
64 EVT_PL_START_BAR_DRAGGING ( cbBarDragPlugin::OnStartBarDragging )
65 EVT_PL_LEFT_DCLICK ( cbBarDragPlugin::OnLDblClick )
66
67END_EVENT_TABLE()
68
69cbBarDragPlugin::cbBarDragPlugin(void)
70
71 : mBarDragStarted ( FALSE ),
72 mCanStick ( TRUE ),
73 mpScrDc ( NULL ),
74 mpCurCursor ( NULL ),
75 mpDraggedBar ( NULL ),
76 mInClientHintBorder( 4 )
77{}
78
79cbBarDragPlugin::cbBarDragPlugin( wxFrameLayout* pPanel, int paneMask )
80
81 : cbPluginBase( pPanel, paneMask ),
82
83 mBarDragStarted ( FALSE ),
84 mCanStick ( TRUE ),
85 mpScrDc ( NULL ),
86 mpCurCursor ( NULL ),
87 mpDraggedBar ( NULL ),
88 mInClientHintBorder( 4 )
89{}
90
91cbBarDragPlugin::~cbBarDragPlugin()
92{
93 // nothing
94}
95
96// helper methods (protected)
97
98// clips (top/bottom) or (right/left) edges against the frame's bounding rect.
99
100void do_clip_edges( int len, int& rectPos, int& rectLen )
101{
102 if ( rectPos < 0 )
103 {
104 rectLen += rectPos;
105 rectPos = 0;
106 if ( rectLen < 0 )
107 rectLen = 1;
108 }
109 else
110 if ( rectPos > len-1 )
111 {
112 rectPos = len-1;
113 rectLen = 1;
114 }
115 else
116 if ( rectPos + rectLen - 1 > len )
117
118 rectLen -= (rectPos + rectLen) - len + 1;
119}
120
121void cbBarDragPlugin::ClipRectInFrame( wxRect& rect )
122{
123 int w, h;
124 mpLayout->GetParentFrame().GetClientSize( &w, &h );
125
126 do_clip_edges( w, rect.x, rect.width );
127 do_clip_edges( h, rect.y, rect.height );
128}
129
130void cbBarDragPlugin::ClipPosInFrame( wxPoint& pos )
131{
132 int w, h;
133 mpLayout->GetParentFrame().GetClientSize( &w, &h );
134
135 if ( pos.x < 0 )
136 pos.x = 0;
137 if ( pos.y < 0 )
138 pos.y = 0;
139 if ( pos.x > w )
140 pos.x = w-1;
141 if ( pos.y > h )
142 pos.y = h-1;
143}
144
145void cbBarDragPlugin::AdjustHintRect( wxPoint& mousePos )
146{
147 mHintRect.x = mousePos.x - mMouseInRectX;
148 mHintRect.y = mousePos.y - mMouseInRectY;
149}
150
151cbDockPane* cbBarDragPlugin::HitTestPanes( wxRect& rect )
152{
153 //wxRect clipped = rect;
154
155 //ClipRectInFrame( clipped );
156
157 cbDockPane** pPanes = mpLayout->GetPanesArray();
158
159 for( int i = 0; i != MAX_PANES; ++i )
160
161 if ( rect_hits_rect( pPanes[i]->mBoundsInParent, rect ) )
162
163 return pPanes[i];
164
165 return NULL;
166}
167
168cbDockPane* cbBarDragPlugin::HitTestPanes( wxPoint& pos )
169{
170 wxPoint clipped = pos;
171
172 //ClipPosInFrame( pos );
173
174 cbDockPane** pPanes = mpLayout->GetPanesArray();
175
176 for( int i = 0; i != MAX_PANES; ++i )
177
178 if ( rect_contains_point( pPanes[i]->mBoundsInParent, clipped.x, clipped.y ) )
179
180 return pPanes[i];
181
182 return NULL;
183}
184
185bool cbBarDragPlugin::HitsPane( cbDockPane* pPane, wxRect& rect )
186{
187 return rect_hits_rect( pPane->mBoundsInParent, rect );
188}
189
190int cbBarDragPlugin::GetDistanceToPane( cbDockPane* pPane, wxPoint& mousePos )
191{
192 wxRect& bounds = pPane->mBoundsInParent;
193
194 switch( pPane->mAlignment )
195 {
196 case FL_ALIGN_TOP : return mousePos.y - ( bounds.y + bounds.height );
197
198 case FL_ALIGN_BOTTOM : return bounds.y - mousePos.y;
199
200 case FL_ALIGN_LEFT : return mousePos.x - ( bounds.x + bounds.width );
201
202 case FL_ALIGN_RIGHT : return bounds.x - mousePos.x;
203
204 default : return 0; // never reached
205 }
206
207// return 0;
208}
209
210bool cbBarDragPlugin::IsInOtherPane( wxPoint& mousePos )
211{
212 cbDockPane* pPane = HitTestPanes( mousePos );
213
214 if ( pPane && pPane != mpCurPane ) return TRUE;
215 else return FALSE;
216}
217
218bool cbBarDragPlugin::IsInClientArea( wxPoint& mousePos )
219{
220 return ( HitTestPanes( mousePos ) == NULL );
221}
222
223bool cbBarDragPlugin::IsInClientArea( wxRect& rect )
224{
225 return ( HitTestPanes( rect ) == NULL );
226}
227
228void cbBarDragPlugin::CalcOnScreenDims( wxRect& rect )
229{
230 if ( !mpCurPane || mpDraggedBar->IsFixed() ) return;
231
232 wxRect inPane = rect;
233
234 mpCurPane->FrameToPane( &inPane );
235
236 int rowNo = mpCurPane->GetRowAt( inPane.y, inPane.y + inPane.height );
237
238 bool isMaximized = ( rowNo >= (int)mpCurPane->GetRowList().Count() || rowNo < 0 );
239
240 if ( isMaximized )
241 {
242 inPane.x = 0;
243 inPane.width = mpCurPane->mPaneWidth;
244
245 mpCurPane->PaneToFrame( &inPane );
246
247 rect = inPane;
248 }
249}
250
251// helpers
252
253static inline void check_upper_overrun( int& pos, int width, int mousePos )
254{
255 if ( mousePos >= pos + width )
256
257 pos = mousePos - width/2;
258}
259
260static inline void check_lower_overrun( int& pos, int width, int mousePos )
261{
262 if ( mousePos <= pos )
263
264 pos = mousePos - width/2;
265}
266
267void cbBarDragPlugin::StickToPane( cbDockPane* pPane, wxPoint& mousePos )
268{
269 int wInPane = GetBarWidthInPane ( pPane );
270 int hInPane = GetBarHeightInPane( pPane );
271
272 // adjsut hint-rect horizontally (in pane's orientation)
273
274 if ( pPane->IsHorizontal() )
275 {
276 mHintRect.width = wInPane;
277 mHintRect.height = hInPane;
278 }
279 else
280 {
281 mHintRect.height = wInPane;
282 mHintRect.width = hInPane;
283 }
284
285 // adjsut hint-rect vertically (in pane's orientation)
286
287 wxRect& bounds = pPane->mBoundsInParent;
288
289 // TRUE, if hint enters the pane through it's lower edge
290
291 bool fromLowerEdge = ( pPane->IsHorizontal() )
292 ? mousePos.y > bounds.y
293 : mousePos.x > bounds.x;
294
295 // NOTE:: about all the below min/max things: they are meant to ensure
4cbc57f0
JS
296 // that the mouse pointer doesn't overrun (leave) the hint-rectangle
297 // when its dimensions are recalculated upon sticking it to the pane
8e08b761
JS
298
299 if ( pPane->IsHorizontal() && fromLowerEdge )
300 {
301 int paneBottomEdgeY = bounds.y + bounds.height;
302
303 mHintRect.y = wxMin( paneBottomEdgeY, mousePos.y );
304
305 check_lower_overrun( mHintRect.y, hInPane, mousePos.y );
306
307 }
308 else
309 if ( pPane->IsHorizontal() && !fromLowerEdge )
310 {
311 int paneTopEdgeY = bounds.y;
312
313 mHintRect.y = wxMax( paneTopEdgeY - hInPane, mousePos.y - hInPane );
314
315 check_upper_overrun( mHintRect.y, hInPane, mousePos.y );
316 }
317 else
318 if ( !pPane->IsHorizontal() && fromLowerEdge )
319 {
320 int paneRightEdgeX = bounds.x + bounds.width;
321
322 mHintRect.x = wxMin( paneRightEdgeX, mousePos.x );
323
324 check_lower_overrun( mHintRect.x, hInPane, mousePos.x );
325 }
326 else
327 if ( !pPane->IsHorizontal() && !fromLowerEdge )
328 {
329 int paneLeftEdgeX = bounds.x;
330
331 mHintRect.x = wxMax( paneLeftEdgeX - hInPane, mousePos.x - hInPane );
332
333 check_upper_overrun( mHintRect.x, hInPane, mousePos.x );
334 }
335
336 mMouseInRectX = mousePos.x - mHintRect.x;
337 mMouseInRectY = mousePos.y - mHintRect.y;
338
339 mpCurPane = pPane; // memorize pane to which the hint is currently sticked
340}
341
342void cbBarDragPlugin::UnstickFromPane( cbDockPane* pPane, wxPoint& mousePos )
343{
4cbc57f0 344 // unsticking causes rectangle to get the shape in which
8e08b761
JS
345 // dragged control-bar would be when floated
346
8e08b761
JS
347 int newWidth = mpDraggedBar->mDimInfo.mSizes[wxCBAR_FLOATING].x;
348 int newHeight = mpDraggedBar->mDimInfo.mSizes[wxCBAR_FLOATING].y;
349
350 wxRect& flBounds = mpDraggedBar->mDimInfo.mBounds[wxCBAR_FLOATING];
351
352 if ( flBounds.width != -1 )
353 {
354 newWidth = flBounds.width;
355 newHeight = flBounds.height;
356 }
357
358 mHintRect.width = newWidth;
359 mHintRect.height = newHeight;
360
361 wxRect& bounds = pPane->mBoundsInParent;
362
363 // TRUE, if hint leaves the pane through it's lower edge
364
365 bool fromLowerEdge = ( pPane->IsHorizontal() )
366 ? mousePos.y > bounds.y
367 : mousePos.x > bounds.x;
368
369 // NOTE:: ...all the below min/max things - see comments about it in StickToPane(..)
370
371 if ( pPane->IsHorizontal() && fromLowerEdge )
372 {
11a68fa3 373// bool fromLowerEdge = mousePos.y > bounds.y;
8e08b761
JS
374
375 mHintRect.y = wxMax( bounds.y + bounds.height + 1, mousePos.y - newHeight );
376
377 check_upper_overrun( mHintRect.y, newHeight, mousePos.y );
378
379 // this is how MFC's hint behaves:
380
381 if ( mMouseInRectX > newWidth )
382
383 mHintRect.x = mousePos.x - ( newWidth / 2 );
384 }
385 else
386 if ( pPane->IsHorizontal() && !fromLowerEdge )
387 {
388 mHintRect.y = wxMin( bounds.y - newHeight - 1, mousePos.y );
389
390 // -/-
391
392 if ( mMouseInRectX > newWidth )
393
394 mHintRect.x = mousePos.x - ( newWidth / 2 );
395
396 check_lower_overrun( mHintRect.y, newHeight, mousePos.y );
397 }
398 else
399 if ( !pPane->IsHorizontal() && fromLowerEdge )
400 {
401 mHintRect.x = wxMax( bounds.x + bounds.width, mousePos.x - newWidth );
402
403 // -/-
404
405 if ( mMouseInRectY > newHeight )
406
407 mHintRect.y = mousePos.y - ( newHeight / 2 );
408
409 check_upper_overrun( mHintRect.x, newWidth, mousePos.x );
410 }
411 else
412 if ( !pPane->IsHorizontal() && !fromLowerEdge )
413 {
414 mHintRect.x = wxMin( bounds.x - newWidth - 1, mousePos.x );
415
416 // -/-
417
418 if ( mMouseInRectY > newHeight )
419
420 mHintRect.y = mousePos.y - ( newHeight / 2 );
421
422 check_lower_overrun( mHintRect.x, newWidth, mousePos.x );
423 }
424
425 mMouseInRectX = mousePos.x - mHintRect.x;
426 mMouseInRectY = mousePos.y - mHintRect.y;
427
428 mpCurPane = NULL;
429}
430
431int cbBarDragPlugin::GetBarWidthInPane( cbDockPane* pPane )
432{
433 if ( pPane == mpSrcPane )
434
435 return mBarWidthInSrcPane;
436
437 // this is how MFC's bars behave:
438
439 if ( pPane->IsHorizontal() )
440
441 return mpDraggedBar->mDimInfo.mSizes[wxCBAR_DOCKED_HORIZONTALLY].x;
442 else
443 return mpDraggedBar->mDimInfo.mSizes[wxCBAR_DOCKED_VERTICALLY ].x;
444}
445
446int cbBarDragPlugin::GetBarHeightInPane( cbDockPane* pPane )
447{
448 if ( pPane->IsHorizontal() )
449
450 return mpDraggedBar->mDimInfo.mSizes[wxCBAR_DOCKED_HORIZONTALLY].y;
451 else
452 return mpDraggedBar->mDimInfo.mSizes[wxCBAR_DOCKED_VERTICALLY ].y;
453}
454
455void cbBarDragPlugin::ShowHint( bool prevWasInClient )
456{
457 bool wasDocked = FALSE;
458
8e08b761
JS
459
460 if ( mpSrcPane->mProps.mRealTimeUpdatesOn == FALSE )
461 {
4cbc57f0 462 // do heavy calculations first
8e08b761
JS
463
464 wxRect actualRect = mHintRect; // will be adjusted depending on drag-settings
465
466 if ( mpSrcPane->mProps.mExactDockPredictionOn && mpCurPane )
467 {
8552e6f0
MB
468 #ifdef __WXDEBUG__
469 bool success =
470 #endif
471 mpLayout->RedockBar( mpDraggedBar, mHintRect, mpCurPane, FALSE );
8e08b761
JS
472
473 wxASSERT( success ); // DBG::
474
475 actualRect = mpDraggedBar->mBounds;
476
477 mpCurPane->PaneToFrame( &actualRect );
478 }
479 else
480 CalcOnScreenDims( actualRect );
481
482 // release previous hint
483
484 if ( mPrevHintRect.x != POS_UNDEFINED )
485 {
486 // erase previous rectangle
487
488 cbDrawHintRectEvent evt( mPrevHintRect, prevWasInClient, TRUE, FALSE );
489
490 mpLayout->FirePluginEvent( evt );
491 }
492
493 // draw new hint
494
495 cbDrawHintRectEvent evt( actualRect, mpCurPane == NULL, FALSE, FALSE );
496
497 mpLayout->FirePluginEvent( evt );
498
499 mPrevHintRect = actualRect;
500 }
501 else
502 {
503 // otherwise, if real-time updates option is ON
504
879da8c8
JS
505 if ( mpDraggedBar->mState != wxCBAR_FLOATING && !mpCurPane )
506 {
507 mpLayout->SetBarState( mpDraggedBar, wxCBAR_FLOATING, TRUE );
508 }
509 else
510 if ( mpDraggedBar->mState == wxCBAR_FLOATING && mpCurPane )
511 {
512 mpLayout->SetBarState( mpDraggedBar, wxCBAR_DOCKED_HORIZONTALLY, FALSE );
513
514 wasDocked = TRUE;
515 }
516
8e08b761
JS
517 if ( mpCurPane )
518 {
519 mpLayout->GetUpdatesManager().OnStartChanges();
520
521 if ( wasDocked )
522
523 mpDraggedBar->mUMgrData.SetDirty( TRUE );
524
8552e6f0
MB
525 #ifdef __WXDEBUG__
526 bool success =
527 #endif
528 mpLayout->RedockBar( mpDraggedBar, mHintRect, mpCurPane, FALSE );
8e08b761
JS
529
530 wxASSERT( success ); // DBG ::
531
532 mpLayout->GetUpdatesManager().OnFinishChanges();
533 mpLayout->GetUpdatesManager().UpdateNow();
534 }
535 else
536 {
537 if ( mpLayout->mFloatingOn )
538 {
539 // move the top-most floated bar around as user drags the hint
540
541 mpDraggedBar->mDimInfo.mBounds[ wxCBAR_FLOATING ] = mHintRect;
542
543 mpLayout->ApplyBarProperties( mpDraggedBar );
544 }
545 }
546 }
547}
548
549/*** event handlers ***/
550
551void cbBarDragPlugin::OnMouseMove( cbMotionEvent& event )
552{
553 // calculate postion in frame's coordiantes
554
555 if ( !mBarDragStarted )
556 {
557 event.Skip(); // pass event to the next plugin
558 return;
559 }
560
561 wxPoint mousePos = event.mPos;
562
563 event.mpPane->PaneToFrame( &mousePos.x, &mousePos.y );
564
565 bool prevIsInClient = ( mpCurPane == 0 );
566
567 AdjustHintRect( mousePos );
568
569 // if the hint-rect is not "tempted" to any pane yet
570
571 if ( mpCurPane == NULL )
572 {
573 cbDockPane* pPane = HitTestPanes( mHintRect );
574
575 if ( !pPane )
576
577 // enable sticking again, if we've left the pane completely
578 mCanStick = TRUE;
579
580 if ( mCanStick && pPane &&
581 GetDistanceToPane( pPane, mousePos ) < GetBarHeightInPane( pPane ) )
582
583 StickToPane( pPane, mousePos );
584 else
585 if ( pPane && HitTestPanes( mousePos ) == pPane && 0 ) // FOR NOW:: disabled
586
587 StickToPane( pPane, mousePos );
588 }
589 else
590 {
591 // otherwise, when rect is now sticked to some of the panes
592 // check if it should still remain in this pane
593
594 mCanStick = TRUE;
595
596 bool mouseInOther = IsInOtherPane( mousePos );
597
598 if ( mouseInOther )
599 {
600 cbDockPane* pPane = HitTestPanes( mousePos );
601
602 StickToPane( pPane, mousePos );
603 }
604 else
605 {
606 if ( IsInClientArea( mousePos ) )
607 {
608 cbDockPane* pPane = HitTestPanes( mHintRect );
609
610 if ( pPane &&
611 pPane != mpCurPane &&
612 GetDistanceToPane( pPane, mousePos ) < GetBarHeightInPane( pPane ) )
613
614 StickToPane( pPane, mousePos );
615 else
616 if ( !pPane )
617 {
618 UnstickFromPane( mpCurPane, mousePos );
619
620 // FOR NOW:: disabled, would cause some mess
621 //mCanStick = FALSE; // prevents from sticking to this
622 // pane again, flag is reset when hint-rect
623 // leaves the pane completely
624 }
625 else
626 if ( GetDistanceToPane( pPane, mousePos ) > GetBarHeightInPane( pPane ) )
627 {
628 if ( !HitsPane( mpCurPane, mHintRect ) )
629 {
630 UnstickFromPane( mpCurPane, mousePos );
631
632 // FOR NOW:: disabled, would cause some mess
633 //mCanStick = FALSE; // prevents from sticking to this
634 // pane again, flag is reset when hint-rect
635 // leaves the pane completely
636 }
637 }
638
639 }
640 else
641 {
642 }
643 }
644 }
645
646 ShowHint( prevIsInClient );
647
648 wxCursor* pPrevCurs = mpCurCursor;
649
650 if ( mpCurPane )
879da8c8
JS
651 {
652 mpCurCursor = mpLayout->mpNormalCursor;
653 }
8e08b761
JS
654 else
655 {
879da8c8
JS
656 // if floating is off, and we are in the client
657 // area, the cursor will be invalid, otherwise
658 // it will be the normal cursor
8e08b761 659
879da8c8
JS
660 if (mpLayout->mFloatingOn)
661 {
662 mpCurCursor = mpLayout->mpNormalCursor;
663 }
8e08b761 664 else
879da8c8 665 {
8e08b761
JS
666 mpCurCursor = mpLayout->mpNECursor;
667 }
879da8c8
JS
668
669 }
8e08b761 670 if ( pPrevCurs != mpCurCursor )
8e08b761
JS
671 mpLayout->GetParentFrame().SetCursor( *mpCurCursor );
672}
673
674void cbBarDragPlugin::OnLButtonDown( cbLeftDownEvent& event )
675{
676 if ( mBarDragStarted )
677 {
873a543b 678 wxMessageBox(wxT("DblClick!"));
8e08b761
JS
679 }
680
681 event.Skip();
682}
683
684void cbBarDragPlugin::OnLButtonUp( cbLeftUpEvent& event )
685{
686 if ( mBarDragStarted )
687 {
688 if ( mpSrcPane->mProps.mRealTimeUpdatesOn == FALSE )
689 {
690 // erase current rectangle, and finsih on-screen drawing session
691
692 cbDrawHintRectEvent evt( mPrevHintRect, mpCurPane == NULL, TRUE, TRUE );
693
694 mpLayout->FirePluginEvent( evt );
695
696 if ( mpCurPane != NULL )
697 {
698 if ( mpSrcPane->mProps.mExactDockPredictionOn )
699 {
700 mpLayout->RedockBar( mpDraggedBar, mHintRect, mpCurPane, FALSE );
701
702 mpLayout->GetUpdatesManager().OnFinishChanges();
703 mpLayout->GetUpdatesManager().UpdateNow();
704 }
705 else
879da8c8
JS
706 {
707 if (mpDraggedBar->mState == wxCBAR_FLOATING)
708 {
709 mpLayout->SetBarState( mpDraggedBar, wxCBAR_DOCKED_HORIZONTALLY, TRUE);
710 }
711
8e08b761
JS
712 mpLayout->RedockBar( mpDraggedBar, mHintRect, mpCurPane );
713 }
714 }
879da8c8
JS
715 else
716 {
717 if (mpDraggedBar->mState != wxCBAR_FLOATING)
718 {
719 mpLayout->SetBarState(mpDraggedBar, wxCBAR_FLOATING, true);
720 }
721
722 mpDraggedBar->mDimInfo.mBounds[ wxCBAR_FLOATING ] = mHintRect;
723 mpLayout->ApplyBarProperties( mpDraggedBar );
724 }
725 }
8e08b761
JS
726
727 mHintRect.width = -1;
728
a570d5b3
JS
729 // In Windows, at least, the frame needs to have a null cursor
730 // else child windows (such as text windows) inherit the cursor
731#if 1
732 mpLayout->GetParentFrame().SetCursor( wxNullCursor );
733#else
734 mpLayout->GetParentFrame().SetCursor( *mpLayout->mpNormalCursor );
735#endif
8e08b761
JS
736
737 mpLayout->ReleaseEventsFromPane( event.mpPane );
738 mpLayout->ReleaseEventsFromPlugin( this );
739
740 mBarDragStarted = FALSE;
741
742 if ( mBarWasFloating && mpDraggedBar->mState != wxCBAR_FLOATING )
743 {
744 // save bar's floating position before it was docked
745
746 mpDraggedBar->mDimInfo.mBounds[ wxCBAR_FLOATING ] = mFloatedBarBounds;
747 }
748 }
749 else
750 event.Skip(); // pass event to the next plugin
751}
752
753void cbBarDragPlugin::OnLDblClick( cbLeftDClickEvent& event )
754{
755 int avoidCompilerWarning = 1;
756 if ( avoidCompilerWarning )
757 {
758 cbBarInfo* pHittedBar;
759 cbRowInfo* pRow;
760
761 if ( event.mpPane->HitTestPaneItems( event.mPos, // in pane's coordiantes
762 &pRow,
763 &pHittedBar ) == CB_BAR_CONTENT_HITTED
764 )
765 {
766 mpLayout->SetBarState( pHittedBar, wxCBAR_FLOATING, TRUE );
767
768 mpLayout->RepositionFloatedBar( pHittedBar );
769
770 return; // event is "eaten" by this plugin
771 }
772
773 mBarDragStarted = FALSE;
774
775 event.Skip();
776 }
777
778 //wxMessageBox("Hi, dblclick arrived!");
779}
780
781void cbBarDragPlugin::OnStartBarDragging( cbStartBarDraggingEvent& event )
782{
783 mpDraggedBar = event.mpBar;
784 mpSrcPane = event.mpPane;
785
786 mpLayout->CaptureEventsForPane( event.mpPane );
787 mpLayout->CaptureEventsForPlugin( this );
788
879da8c8 789 mpLayout->GetParentFrame().SetCursor( *mpLayout->mpNormalCursor );
8e08b761
JS
790
791 mBarDragStarted = TRUE;
792
793 wxRect inParent = mpDraggedBar->mBounds;
794
795 mBarWasFloating = mpDraggedBar->mState == wxCBAR_FLOATING;
796
797 if ( mBarWasFloating )
798 {
799 inParent = mpDraggedBar->mDimInfo.mBounds[ wxCBAR_FLOATING ];
800 mFloatedBarBounds = inParent;
801 }
802 else
803 event.mpPane->PaneToFrame( &inParent );
804
805 mHintRect.x = POS_UNDEFINED;
806
807 mHintRect.width = inParent.width;
808 mHintRect.height = inParent.height;
809
810 mMouseInRectX = event.mPos.x - inParent.x;
811 mMouseInRectY = event.mPos.y - inParent.y;
812
813 mpSrcPane = event.mpPane;
814
815 if ( mpDraggedBar->mState == wxCBAR_FLOATING )
816
817 mpCurPane = NULL;
818 else
819 mpCurPane = event.mpPane;
820
821 mPrevHintRect.x = POS_UNDEFINED;
822
823 mCanStick = FALSE; // we're not stuck into any pane now -
824 // there's nowhere to "stick-twice"
825
826 mBarWidthInSrcPane = mpDraggedBar->mDimInfo.mSizes[ mpDraggedBar->mState ].x;
827
828 if ( mpSrcPane->mProps.mRealTimeUpdatesOn == FALSE &&
829 mpSrcPane->mProps.mExactDockPredictionOn )
830
831 mpLayout->GetUpdatesManager().OnStartChanges(); // capture initial state of layout
832
833 // simulate the first mouse movement
834
835 int x = event.mPos.x, y = event.mPos.y;
836
837 mpSrcPane->FrameToPane( &x, &y );
838
839 cbMotionEvent motionEvt( wxPoint(x,y), event.mpPane );
840
841
842 this->OnMouseMove( motionEvt );
843
844 return; // event is "eaten" by this plugin
845}
846
847/*** on-screen hint-tracking related methods ***/
848
849void cbBarDragPlugin::OnDrawHintRect( cbDrawHintRectEvent& event )
850{
851 if ( !mpScrDc ) StartTracking();
852
853 DoDrawHintRect( event.mRect, event.mIsInClient );
854
855 if ( event.mLastTime )
856
857 FinishTracking();
858}
859
860#define _IMG_A 0xAA // Note: modified from _A to _IMG_A, _A was already defined (cygwin)
861#define _IMG_B 0x00 // Note: modified from _B to _IMG_A, _B was already defined (cygwin)
862#define _IMG_C 0x55 // Note: modified from _C to _IMG_C, for consistency reasons.
863#define _IMG_D 0x00 // Note: modified from _D to _IMG_D, for consistency reasons.
864
865// FOR NOW:: static
866
867static const unsigned char _gCheckerImg[16] = { _IMG_A,_IMG_B,_IMG_C,_IMG_D,
868 _IMG_A,_IMG_B,_IMG_C,_IMG_D,
869 _IMG_A,_IMG_B,_IMG_C,_IMG_D,
870 _IMG_A,_IMG_B,_IMG_C,_IMG_D
871 };
872
873void cbBarDragPlugin::StartTracking()
874{
875 mpScrDc = new wxScreenDC;
876
877 wxScreenDC::StartDrawingOnTop(&mpLayout->GetParentFrame());
878}
879
880void cbBarDragPlugin::DoDrawHintRect( wxRect& rect, bool isInClientRect)
881{
882 wxRect scrRect;
883
884 RectToScr( rect, scrRect );
885
886 int prevLF = mpScrDc->GetLogicalFunction();
887
888 mpScrDc->SetLogicalFunction( wxINVERT );
889
890 if ( isInClientRect )
891 {
892 // BUG BUG BUG (wx):: somehow stippled brush works only
893 // when the bitmap created on stack, not
894 // as a member of the class
895
896 wxBitmap checker( (const char*)_gCheckerImg, 8,8 );
897
898 wxBrush checkerBrush( checker );
899
900 mpScrDc->SetPen( mpLayout->mNullPen );
901 mpScrDc->SetBrush( checkerBrush );
902
903 int half = mInClientHintBorder / 2;
904
905 mpScrDc->DrawRectangle( scrRect.x - half, scrRect.y - half,
906 scrRect.width + 2*half, mInClientHintBorder );
907
908 mpScrDc->DrawRectangle( scrRect.x - half, scrRect.y + scrRect.height - half,
909 scrRect.width + 2*half, mInClientHintBorder );
910
911 mpScrDc->DrawRectangle( scrRect.x - half, scrRect.y + half - 1,
912 mInClientHintBorder, scrRect.height - 2*half + 2);
913
914 mpScrDc->DrawRectangle( scrRect.x + scrRect.width - half,
915 scrRect.y + half - 1,
916 mInClientHintBorder, scrRect.height - 2*half + 2);
917
918 mpScrDc->SetBrush( wxNullBrush );
919 }
920 else
921 {
922 mpScrDc->SetPen( mpLayout->mBlackPen );
923
924 mpScrDc->DrawLine( scrRect.x, scrRect.y,
925 scrRect.x + scrRect.width, scrRect.y );
926
927 mpScrDc->DrawLine( scrRect.x, scrRect.y + 1,
928 scrRect.x, scrRect.y + scrRect.height );
929
930 mpScrDc->DrawLine( scrRect.x+1, scrRect.y + scrRect.height,
931 scrRect.x + scrRect.width, scrRect.y + scrRect.height );
932
933 mpScrDc->DrawLine( scrRect.x + scrRect.width , scrRect.y,
934 scrRect.x + scrRect.width, scrRect.y + scrRect.height + 1);
935 }
936
937 mpScrDc->SetLogicalFunction( prevLF );
938}
939
940void cbBarDragPlugin::DrawHintRect ( wxRect& rect, bool isInClientRect)
941{
942 DoDrawHintRect( rect, isInClientRect );
943}
944
945void cbBarDragPlugin::EraseHintRect( wxRect& rect, bool isInClientRect)
946{
947 DoDrawHintRect( rect, isInClientRect );
948}
949
950void cbBarDragPlugin::FinishTracking()
951{
952 wxScreenDC::EndDrawingOnTop();
953
954 delete mpScrDc;
955
956 mpScrDc = NULL;
957}
958
959void cbBarDragPlugin::RectToScr( wxRect& frameRect, wxRect& scrRect )
960{
961 scrRect = frameRect;
962
963 int x = frameRect.x, y = frameRect.y;
964
965 mpLayout->GetParentFrame().ClientToScreen( &x, &y );
966
967 scrRect.x = x;
968 scrRect.y = y;
969}
970