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