1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "rowlayoutpl.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/fl/rowlayoutpl.h"
29 // exerimental "features" are still buggy
32 /***** Implementation for class cbRowLayoutPlugin *****/
34 IMPLEMENT_DYNAMIC_CLASS( cbRowLayoutPlugin
, cbPluginBase
)
36 BEGIN_EVENT_TABLE( cbRowLayoutPlugin
, cbPluginBase
)
38 EVT_PL_LAYOUT_ROW ( cbRowLayoutPlugin::OnLayoutRow
)
39 EVT_PL_LAYOUT_ROWS( cbRowLayoutPlugin::OnLayoutRows
)
40 EVT_PL_RESIZE_ROW ( cbRowLayoutPlugin::OnResizeRow
)
42 EVT_PL_INSERT_BAR ( cbRowLayoutPlugin::OnInsertBar
)
43 EVT_PL_REMOVE_BAR ( cbRowLayoutPlugin::OnRemoveBar
)
47 cbRowLayoutPlugin::cbRowLayoutPlugin(void)
51 cbRowLayoutPlugin::cbRowLayoutPlugin( wxFrameLayout
* pPanel
, int paneMask
)
53 : cbPluginBase( pPanel
, paneMask
),
57 void cbRowLayoutPlugin::CheckIfAtTheBoundary( cbBarInfo
* pTheBar
, cbRowInfo
& rowInfo
)
59 // this method handles situation, when fixed bar is inserted
60 // into the row, where among fixed bars not-fixed ones are present.
61 // In this case we need to check if the pBarNode appears to be inserted
62 // chain of fixed-bars on the very right or left side of the row,
63 // then all the white-space, such chain should be eliminated,
64 // and the resulting chain justified to the right or the left
67 if ( !pTheBar
->IsFixed() || rowInfo
.mHasOnlyFixedBars
)
71 cbBarInfo
* pBar
= rowInfo
.mBars
[ rowInfo
.mBars
.Count() - 1 ];
73 // slide fixed bars to the right on the right side relative to the pBarNode
75 int prevX
= mpPane
->mPaneWidth
;
79 if ( !pBar
->IsFixed() )
82 wxRect
& bounds
= pBar
->mBounds
;
84 bounds
.x
= prevX
- bounds
.width
;
88 if ( pBar
== pTheBar
) break;
94 // slide fixed bars to the left on the left side relative to the pBarNode
96 pBar
= rowInfo
.mBars
[0];
102 if ( pBar
->IsFixed() )
106 wxRect
& bounds
= pBar
->mBounds
;
110 prevX
= bounds
.x
+ bounds
.width
;
112 if ( pBar
== pTheBar
) break;
119 void cbRowLayoutPlugin::ExpandNotFixedBars( cbRowInfo
* pRow
)
121 ApplyLengthRatios( pRow
);
123 // FIXME:: something's wrong?
126 double freeSpc
= (double)GetRowFreeSpace( pRow
);
128 // calculate sum of precents
130 double pcntSum
= 0.0;
133 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
135 if ( !pRow
->mBars
[i
]->IsFixed() )
136 pcntSum
+= pRow
->mBars
[i
]->mLenRatio
;
143 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
145 cbBarInfo
& bar
= *pRow
->mBars
[i
];
147 if ( !bar
.IsFixed() )
149 bar
.mLenRatio
= bar
.mLenRatio
/(pcntSum
);
153 wxMax( mpPane
->mProps
.mMinCBarDim
.x
, int( freeSpc
*bar
.mLenRatio
) );
156 bar
.mBounds
.x
= curX
;
157 curX
= bar
.mBounds
.x
+ bar
.mBounds
.width
;
161 void cbRowLayoutPlugin::AdjustLengthOfInserted( cbRowInfo
* pRow
, cbBarInfo
* pTheBar
)
163 return; // TBD: Makes following code unreachable
165 // pTheBar is not-fixed
168 // FIXME:: what is this for??
175 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
177 if ( !pRow
->mBars
[i
]->IsFixed() )
178 totalLen
+= pRow
->mBars
[i
]->mBounds
.width
;
181 double curWidth
= pTheBar
->mBounds
.width
;
183 if ( pRow
->mBars
.Count() )
185 pTheBar
->mBounds
.width
= int( mpPane
->mPaneWidth
* (curWidth
/ double(totalLen
)) );
188 double freeSpc
= (double)GetRowFreeSpace( pRow
);
190 double pcntSum
= 0.0;
193 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
195 if ( !pRow
->mBars
[i
]->IsFixed() )
196 pcntSum
+= pRow
->mBars
[i
]->mLenRatio
;
199 // if no longer "balanced", assume that `pTheBar' was previously
200 // removed from this row (kind of AI...)
202 if ( pcntSum
< 0.98 )
204 pTheBar
->mBounds
.width
= freeSpc
* (1.0 - pcntSum
);
208 void cbRowLayoutPlugin::FitBarsToRange( int from
, int till
,
209 cbBarInfo
* pTheBar
, cbRowInfo
* pRow
)
211 cbBarInfo
* pFromBar
= NULL
;
212 cbBarInfo
* pTillBar
= NULL
;
214 if ( pTheBar
->mBounds
.x
> from
)
216 // it's range from the left
217 pFromBar
= pRow
->mBars
[0];
222 pFromBar
= pTheBar
->mpNext
;
226 // calc free space in the range
228 cbBarInfo
* pBar
= pFromBar
;
229 int freeSpc
= till
-from
;
232 while( pBar
!= pTillBar
)
234 if ( pBar
->IsFixed() )
235 freeSpc
-= pBar
->mBounds
.width
;
237 pcntSum
+= pBar
->mLenRatio
;
242 // adjust not-fixed bar sizes in the range
246 while ( pBar
!= pTillBar
)
248 if ( !pBar
->IsFixed() )
250 pBar
->mBounds
.width
=
251 wxMax( mpPane
->mProps
.mMinCBarDim
.x
,
252 int( double(freeSpc
) * (pBar
->mLenRatio
/pcntSum
) )
258 // layout range, starting from the left-most bar
262 bool hasNotFixedBars
= FALSE
;
264 while ( pBar
!= pTillBar
)
266 wxRect
& bounds
= pBar
->mBounds
;
268 if ( !pBar
->IsFixed() )
270 hasNotFixedBars
= TRUE
;
272 freeSpc
-= bounds
.width
;
277 prevX
= bounds
.x
+ bounds
.width
;
282 // make width adjustment for the right-most bar in the range, due to
283 // lost precision when seting widths using f.p. length-ratios
285 if ( hasNotFixedBars
)
287 if ( pTheBar
->mBounds
.x
> from
)
289 if ( pTillBar
->mpPrev
)
291 wxRect
& tillBar
= pTillBar
->mpPrev
->mBounds
;
293 //tillBar.width = bar.mBounds.x - tillBar.x;
294 tillBar
.width
+= freeSpc
;
299 cbBarInfo
* pLast
= pRow
->mBars
[ pRow
->mBars
.Count() - 1 ];
301 if ( pLast
!= pTheBar
)
303 pTheBar
->mBounds
.width
+= freeSpc
;
305 SlideRightSideBars( pTheBar
);
311 void cbRowLayoutPlugin::MinimzeNotFixedBars( cbRowInfo
* pRow
, cbBarInfo
* pBarToPreserve
)
314 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
316 if ( !pRow
->mBars
[i
]->IsFixed() && pRow
->mBars
[i
] != pBarToPreserve
)
317 pRow
->mBars
[i
]->mBounds
.width
= mpPane
->mProps
.mMinCBarDim
.x
;
321 int cbRowLayoutPlugin::GetRowFreeSpace( cbRowInfo
* pRow
)
323 int freeSpc
= mpPane
->mPaneWidth
;
326 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
328 // not-fixed bars variable length, thus their
329 // dimensions are ignored
330 if ( pRow
->mBars
[i
]->IsFixed() )
331 freeSpc
-= pRow
->mBars
[i
]->mBounds
.width
;
337 void cbRowLayoutPlugin::RecalcLengthRatios( cbRowInfo
* pRow
)
339 double freeSpc
= double( GetRowFreeSpace( pRow
) );
341 cbBarInfo
* pBar
= pRow
->mBars
[0];
342 cbBarInfo
* pLastNotFixed
= NULL
;
344 double pcntLeft
= 1.0; // (100%)
346 #ifdef __EXPERIMENTAL
351 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
353 if ( !pRow
->mBars
[i
]->IsFixed() )
354 totalLen
+= pRow
->mBars
[i
]->mBounds
.width
;
359 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
361 cbBarInfo
& bar
= *pRow
->mBars
[i
];
363 if ( !bar
.IsFixed() )
366 #ifdef __EXPERIMENTAL
368 bar
.mLenRatio
= double(bar
.mBounds
.width
)/double(totalLen
);
370 bar
.mLenRatio
= double(bar
.mBounds
.width
)/freeSpc
;
373 pcntLeft
-= bar
.mLenRatio
;
374 pLastNotFixed
= pBar
;
378 // attach remainder (the result of lost precision) to the
379 // last not-fixed bar
381 #if !defined(__EXPERIMENTAL)
385 pLastNotFixed
->mLenRatio
+= pcntLeft
;
390 void cbRowLayoutPlugin::ApplyLengthRatios( cbRowInfo
* pRow
)
394 // FOR NOW:: all-in-one
397 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
399 if ( !pRow
->mBars
[i
]->IsFixed() )
400 pcntSum
+= pRow
->mBars
[i
]->mLenRatio
;
404 pBar = node_to_first_bar_node( pRow );
408 cbBarInfo& bar = node_to_bar( pBar );
410 if ( !bar.IsFixed() )
412 bar.mLenRatio = pcntSum / bar.mLenRatio;
419 double freeSpc
= GetRowFreeSpace( pRow
);
421 // tricky stuff (improtant!):
422 // when not-fixed bar is removed from the row and there are
423 // still some other not-fixed ones left in that row, then
424 // the sum of mLenRatio's is no longer 1.0 - this is left
425 // intintionally to handle the case when the removed bar
426 // is returned right back to the row - so that it would retain
427 // it's original dimensions in this row (this is kind of AI...)
429 // The problem is - when it's remvoed, the sum of
430 // mLenRatio's is not in "balance", i.e. is < 1.0,
431 // it's possible to restore balance, but instead of that
432 // we artifically ajdust freeSpc value in a way that it would
433 // look like total of mLetRatio's is 1.0, thus original
434 // len. ratios are _preserved_:
436 double unit
= freeSpc
/ pcntSum
;
438 bool haveSquished
= FALSE
;
440 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
442 if ( !pRow
->mBars
[i
]->IsFixed() )
444 cbBarInfo
& bar
= *pRow
->mBars
[i
];
446 if ( int( unit
* bar
.mLenRatio
) < mpPane
->mProps
.mMinCBarDim
.x
)
450 bar
.mBounds
.width
= -1; // mark as "squished"
452 pcntSum
-= bar
.mLenRatio
;
454 freeSpc
-= mpPane
->mProps
.mMinCBarDim
.x
;
460 unit
= freeSpc
/ pcntSum
;
462 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
464 cbBarInfo
& bar
= *pRow
->mBars
[i
];
466 bar
.mBounds
.x
= prevX
;
468 if ( !bar
.IsFixed() )
470 if ( bar
.mBounds
.width
== -1 )
472 bar
.mBounds
.width
= mpPane
->mProps
.mMinCBarDim
.x
;
474 bar
.mBounds
.width
= int( unit
* bar
.mLenRatio
);
476 // a little bit of AI:
477 // memorize bar's height and width, when docked in
478 // the current orientation - by making the current
479 // dimensions to be "preffered" ones for this docking state
481 if ( !bar
.IsFixed() )
483 bar
.mDimInfo
.mSizes
[ bar
.mState
].x
= bar
.mBounds
.width
;
484 bar
.mDimInfo
.mSizes
[ bar
.mState
].y
= bar
.mBounds
.height
;
488 prevX
= bar
.mBounds
.x
+ bar
.mBounds
.width
;
492 void cbRowLayoutPlugin::DetectBarHandles( cbRowInfo
* pRow
)
494 // first pass from left to right (detect left-side handles)
496 bool foundNotFixed
= FALSE
;
499 for ( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
501 cbBarInfo
& bar
= *pRow
->mBars
[i
];
503 bar
.mHasLeftHandle
= FALSE
;
505 if ( !bar
.IsFixed() )
510 bar
.mpPrev
->IsFixed() )
512 bar
.mHasLeftHandle
= TRUE
;
514 foundNotFixed
= TRUE
;
518 // pass from right to left (detect right-side handles)
520 foundNotFixed
= FALSE
;
522 cbBarInfo
* pBar
= pRow
->mBars
[ pRow
->mBars
.Count() - 1 ];
526 pBar
->mHasRightHandle
= FALSE
;
528 if ( !pBar
->IsFixed() )
534 pBar
->mHasRightHandle
= TRUE
;
536 foundNotFixed
= TRUE
;
543 void cbRowLayoutPlugin::RelayoutNotFixedBarsAround( cbBarInfo
* pTheBar
, cbRowInfo
* pRow
)
545 if ( !pTheBar
->mpPrev
)
547 if ( !pTheBar
->IsFixed() )
549 // this bar the first in the row, move it's
550 // left edge to the very left
551 pTheBar
->mBounds
.width
+= pTheBar
->mBounds
.x
;
552 pTheBar
->mBounds
.x
= 0;
556 FitBarsToRange( 0, pTheBar
->mBounds
.x
, pTheBar
, pRow
);
558 if ( !pTheBar
->mpNext
)
560 if ( !pTheBar
->IsFixed() )
562 // this bar is the last one, move it's
563 // right edge to the very right
565 pTheBar
->mBounds
.width
= mpPane
->mPaneWidth
- pTheBar
->mBounds
.x
;
569 FitBarsToRange( pTheBar
->mBounds
.x
+ pTheBar
->mBounds
.width
, mpPane
->mPaneWidth
,
574 void cbRowLayoutPlugin::LayoutItemsVertically( cbRowInfo
& row
)
577 for ( i
= 0; i
!= row
.mBars
.Count(); ++i
)
579 cbBarInfo
& bar
= *row
.mBars
[i
];
581 bar
.mBounds
.y
= row
.mRowY
;
583 if ( !bar
.IsFixed() )
585 // make all not-fixed bars of equal height
586 bar
.mBounds
.height
= row
.mRowHeight
;
588 if ( row
.mHasUpperHandle
)
590 bar
.mBounds
.y
+= mpPane
->mProps
.mResizeHandleSize
;
594 int cbRowLayoutPlugin::CalcRowHeight( cbRowInfo
& row
)
599 for ( i
= 0; i
!= row
.mBars
.Count(); ++i
)
601 maxHeight
= wxMax( maxHeight
, row
.mBars
[i
]->mBounds
.height
);
606 void cbRowLayoutPlugin::StickRightSideBars( cbBarInfo
* pToBar
)
608 cbBarInfo
* pBar
= pToBar
->mpNext
;
609 cbBarInfo
* pPrev
= pToBar
;
613 wxRect
& cur
= pBar
->mBounds
;
614 wxRect
& prev
= pPrev
->mBounds
;
616 cur
.x
= prev
.x
+ prev
.width
;
623 void cbRowLayoutPlugin::SlideLeftSideBars( cbBarInfo
* pTheBar
)
625 // shift left-side-bars to the left (with respect to "theBar"),
626 // so that they would not obscured by each other
628 cbBarInfo
* pBar
= pTheBar
->mpPrev
;
629 cbBarInfo
* pPrev
= pTheBar
;
633 wxRect
& cur
= pBar
->mBounds
;
634 wxRect
& prev
= pPrev
->mBounds
;
636 if ( cur
.x
+ cur
.width
> prev
.x
)
638 cur
.x
= prev
.x
- cur
.width
;
645 void cbRowLayoutPlugin::SlideRightSideBars( cbBarInfo
* pTheBar
)
647 // shift right-side-bars to the right (with respect to "theBar"),
648 // so that they would not be obscured by each other
650 cbBarInfo
* pBar
= pTheBar
->mpNext
;
651 cbBarInfo
* pPrev
= pTheBar
;
655 wxRect
& cur
= pBar
->mBounds
;
656 wxRect
& prev
= pPrev
->mBounds
;
658 if ( cur
.x
< prev
.x
+ prev
.width
)
660 cur
.x
= prev
.x
+ prev
.width
;
667 void cbRowLayoutPlugin::ShiftLeftTrashold( cbBarInfo
* pTheBar
, cbRowInfo
& row
)
669 wxRect
& first
= row
.mBars
[0]->mBounds
;
673 row
.mBars
[0]->mBounds
.x
= 0;
675 SlideRightSideBars( row
.mBars
[0] );
679 void cbRowLayoutPlugin::ShiftRightTrashold( cbBarInfo
* pTheBar
, cbRowInfo
& row
)
681 wxRect
& theBar
= pTheBar
->mBounds
;
685 cbBarInfo
* pBar
= pTheBar
;
687 // calculate free spece on the left side
693 wxRect
& cur
= pBar
->mBounds
;
697 wxRect
& prev
= pBar
->mpPrev
->mBounds
;
699 leftFreeSpc
+= cur
.x
- prev
.x
- prev
.width
;
702 leftFreeSpc
+= cur
.x
;
715 int rightOverflow
= 0;
717 if ( pTheBar
->IsFixed() )
723 wxRect
& cur
= pBar
->mBounds
;
725 if ( cur
.x
+ cur
.width
> mpPane
->mPaneWidth
)
727 rightOverflow
= cur
.x
+ cur
.width
- mpPane
->mPaneWidth
;
733 if ( rightOverflow
> 0 )
735 if ( leftFreeSpc
<= 0 ) return;
737 if ( pTheBar
->mpNext
)
739 wxRect
& next
= pTheBar
->mpNext
->mBounds
;
741 // if there's enough space on the left, move over one half-obscured
742 // bar from the right to the left side with respect to "theBar"
744 if ( next
.width
< leftFreeSpc
)
746 cbBarInfo
* pNext
= pTheBar
->mpNext
;
748 row
.mBars
.Remove( pNext
);
750 row
.mBars
.Insert( pNext
, row
.mBars
.Index( pTheBar
) );
752 next
.x
= theBar
.x
- next
.width
;
754 // re-setup mpPrev/mpNext references after insertion
756 mpPane
->InitLinksForRow( &row
);
760 StickRightSideBars( pTheBar
);
761 SlideLeftSideBars ( pTheBar
);
767 int leftShift
= ( rightOverflow
> leftFreeSpc
)
771 theBar
.x
-= leftShift
;
773 StickRightSideBars( pTheBar
);
774 SlideLeftSideBars ( pTheBar
);
778 } // end of if ( rightOverflow )
785 void cbRowLayoutPlugin::InsertBefore( cbBarInfo
* pBeforeBar
,
791 row
.mBars
.Insert( pTheBar
, row
.mBars
.Index( pBeforeBar
) );
793 row
.mBars
.Add( pTheBar
);
795 pTheBar
->mpRow
= &row
;
798 void cbRowLayoutPlugin::DoInsertBar( cbBarInfo
* pTheBar
, cbRowInfo
& row
)
800 wxRect
& theBar
= pTheBar
->mBounds
;
803 if ( theBar.x < 0 && !node_to_bar( pTheBar ).IsFixed() )
806 theBar.width += theBar.x;
811 for ( i
= 0; i
!= row
.mBars
.Count(); ++i
)
813 cbBarInfo
& bar
= *row
.mBars
[i
];
815 wxRect
& cur
= bar
.mBounds
;
817 // if bar hits the left edge
818 if ( theBar
.x
<= cur
.x
)
820 InsertBefore( &bar
, pTheBar
, row
);
825 // if bar hits the right edge
826 if ( theBar
.x
<= cur
.x
+ cur
.width
)
828 if ( theBar
.x
+ theBar
.width
> cur
.x
+ cur
.width
)
830 InsertBefore( bar
.mpNext
, pTheBar
, row
);
834 // otherwise the bar lies within the bounds of current bar
836 int leftDist
= theBar
.x
- cur
.x
;
837 int rightDist
= cur
.x
+ cur
.width
- (theBar
.x
+ theBar
.width
);
839 if ( leftDist
< rightDist
)
841 InsertBefore( &bar
, pTheBar
, row
);
843 InsertBefore( bar
.mpNext
, pTheBar
, row
);
849 InsertBefore( NULL
, pTheBar
, row
); // insert at the end
854 void cbRowLayoutPlugin::OnInsertBar( cbInsertBarEvent
& event
)
856 cbBarInfo
* pBarToInsert
= event
.mpBar
;
857 cbRowInfo
* pIntoRow
= event
.mpRow
;
858 mpPane
= event
.mpPane
;
860 if ( !pBarToInsert
->IsFixed() )
862 AdjustLengthOfInserted( pIntoRow
, pBarToInsert
);
864 DoInsertBar( pBarToInsert
, *pIntoRow
);
866 mpPane
->InitLinksForRow( pIntoRow
); // relink "mpNext/mpPrev"s
868 // perform relayouting of the bars after insertion
870 // init bar location info
871 pBarToInsert
->mAlignment
= event
.mpPane
->mAlignment
;
872 pBarToInsert
->mRowNo
= event
.mpPane
->GetRowIndex( pIntoRow
);
874 #ifdef __EXPERIMENTAL
876 if ( !pIntoRow
->mHasOnlyFixedBars
|| !pBarToInsert
->IsFixed() )
878 RecalcLengthRatios( pIntoRow
);
882 MinimzeNotFixedBars( pIntoRow
, pBarToInsert
);
884 SlideLeftSideBars ( pBarToInsert
);
885 SlideRightSideBars( pBarToInsert
);
887 ShiftLeftTrashold ( pBarToInsert
, *pIntoRow
);
888 ShiftRightTrashold( pBarToInsert
, *pIntoRow
);
890 mpPane
->SyncRowFlags( pIntoRow
);
892 CheckIfAtTheBoundary( pBarToInsert
, *pIntoRow
);
894 if ( event
.mpPane
->IsHorizontal() )
896 pBarToInsert
->mState
= wxCBAR_DOCKED_HORIZONTALLY
;
898 pBarToInsert
->mState
= wxCBAR_DOCKED_VERTICALLY
;
900 if ( !pIntoRow
->mHasOnlyFixedBars
)
903 #ifdef __EXPERIMENTAL
905 ExpandNotFixedBars( pIntoRow
);
908 RelayoutNotFixedBarsAround( pBarToInsert
, pIntoRow
);
909 RecalcLengthRatios( pIntoRow
);
913 DetectBarHandles( pIntoRow
);
915 // do proportional resizing of not-fixed bars
916 ApplyLengthRatios( pIntoRow
);
919 // adjust the bar's docking state
921 // a little bit of AI:
922 // memorize bar's height and width, when docked in
923 // the current orientation - by making the current
924 // dimensions to be "preferred" ones for this docking state
926 if ( !pBarToInsert
->IsFixed() )
928 cbBarInfo
& bar
= *pBarToInsert
;
930 bar
.mDimInfo
.mSizes
[ bar
.mState
].x
= bar
.mBounds
.width
;
931 bar
.mDimInfo
.mSizes
[ bar
.mState
].y
= bar
.mBounds
.height
;
935 void cbRowLayoutPlugin::OnRemoveBar ( cbRemoveBarEvent
& event
)
937 cbBarInfo
* pBar
= event
.mpBar
;
938 mpPane
= event
.mpPane
;
940 cbRowInfo
* pRow
= pBar
->mpRow
;
942 mpLayout
->GetUpdatesManager().OnBarWillChange( pBar
, pRow
, event
.mpPane
);
944 // invalidate the whole row
945 //pFirst->mpRowInfo->mMgrData.mPrevBounds.x = -1;
947 pRow
->mBars
.Remove( pBar
);
949 // rest bar information after removing it from the row
951 pBar
->mHasLeftHandle
= FALSE
;
952 pBar
->mHasRightHandle
= FALSE
;
954 mpPane
->InitLinksForRow( pRow
); // relink "mpNext/mpPrev"s
956 if ( pRow
->mBars
.Count() == 0 )
958 // empty rows should not exist
960 event
.mpPane
->GetRowList().Remove( pRow
);
964 mpPane
->InitLinksForRows();
968 // force repainting of bars, in the row, from which the bar was removed
970 // FIXME:: really needed?
971 pRow
->mBars
[0]->mUMgrData
.SetDirty(TRUE
);
973 // re-setup mHasOnlyFixedBars flag for the row information
974 event
.mpPane
->SyncRowFlags( pRow
);
976 DetectBarHandles( pRow
);
978 if ( !pRow
->mHasOnlyFixedBars
)
980 ExpandNotFixedBars( pRow
);
984 void cbRowLayoutPlugin::OnLayoutRow( cbLayoutRowEvent
& event
)
986 cbRowInfo
* pRow
= event
.mpRow
;
987 mpPane
= event
.mpPane
;
989 MinimzeNotFixedBars( pRow
, NULL
);
991 if ( !pRow
->mHasOnlyFixedBars
)
993 // do proportional resizing of not-fixed bars
994 ApplyLengthRatios( pRow
);
997 cbBarInfo
& lastBar
= *pRow
->mBars
[ pRow
->mBars
.Count() - 1 ];
998 cbBarInfo
& firstBar
= *pRow
->mBars
[ 0 ];
1000 // FIXME:: Next line not used
1001 // wxRect& bounds = lastBar.mBounds;
1003 if ( lastBar
.mBounds
.x
+ lastBar
.mBounds
.width
> mpPane
->mPaneWidth
)
1005 lastBar
.mBounds
.x
= mpPane
->mPaneWidth
- lastBar
.mBounds
.width
;
1007 // first simulate left-row-edge friction
1009 SlideLeftSideBars( &lastBar
);
1011 if ( firstBar
.mBounds
.x
< 0 )
1012 firstBar
.mBounds
.x
= 0;
1014 // then left-row-edge function, though this
1015 // may cause some of the right-side bars going
1016 // out of row bounds, but left-side always
1017 // has the highest "priority"
1019 SlideRightSideBars( &firstBar
);
1022 event
.Skip(); // pass event to the next handler
1025 void cbRowLayoutPlugin::OnLayoutRows( cbLayoutRowsEvent
& event
)
1027 mpPane
= event
.mpPane
;
1031 // FIXME:: Next line not used.
1032 // RowArrayT& arr = mpPane->GetRowList();
1035 for ( i
= 0; i
!= mpPane
->GetRowList().Count(); ++i
)
1037 cbRowInfo
& row
= *mpPane
->GetRowList()[ i
];
1039 // setup "has-handle" flags for rows, which depend on the existance
1040 // of not-fixed bars in the row
1042 if ( !row
.mHasOnlyFixedBars
)
1044 if ( mpPane
->mAlignment
== FL_ALIGN_TOP
||
1045 mpPane
->mAlignment
== FL_ALIGN_LEFT
)
1047 row
.mHasLowerHandle
= TRUE
;
1049 row
.mHasUpperHandle
= FALSE
;
1053 row
.mHasUpperHandle
= TRUE
;
1055 row
.mHasLowerHandle
= FALSE
;
1060 // otherwise, rows with fixed-bars only, have no height-resizing handles
1061 row
.mHasUpperHandle
= FALSE
;
1062 row
.mHasLowerHandle
= FALSE
;
1065 // setup vertical positions for items in the row
1069 row
.mRowWidth
= mpPane
->mPaneWidth
;
1070 row
.mRowHeight
= CalcRowHeight( row
);
1072 LayoutItemsVertically( row
);
1074 if ( row
.mHasUpperHandle
)
1075 row
.mRowHeight
+= mpPane
->mProps
.mResizeHandleSize
;
1076 if ( row
.mHasLowerHandle
)
1077 row
.mRowHeight
+= mpPane
->mProps
.mResizeHandleSize
;
1079 curY
+= row
.mRowHeight
;
1082 event
.Skip(); // pass event to the next handler - other hookeds plugin
1083 // may also add some "refinements" to the layout now
1086 void cbRowLayoutPlugin::OnResizeRow( cbResizeRowEvent
& event
)
1088 // extract resize-event info
1089 int ofs
= event
.mHandleOfs
;
1090 bool forUpperHandle
= event
.mForUpperHandle
;
1091 cbRowInfo
* pTheRow
= event
.mpRow
;
1092 mpPane
= event
.mpPane
;
1094 // FIXME:: Next line not used.
1095 //int newHeight = pTheRow->mRowHeight;
1099 if ( forUpperHandle
)
1101 // calculate available free space from above,
1102 // which can be obtained by squeezing not-fixed height rows
1104 cbRowInfo
* pRow
= pTheRow
->mpPrev
;
1108 freeSpc
+= pRow
->mRowHeight
- event
.mpPane
->GetMinimalRowHeight( pRow
);
1110 pRow
= pRow
->mpPrev
;
1115 // calculate available free space from below,
1116 // which can be obtained by squeezing not-fixed height rows
1118 cbRowInfo
* pRow
= pTheRow
->mpNext
;
1122 freeSpc
+= pRow
->mRowHeight
- mpPane
->GetMinimalRowHeight( pRow
);
1124 pRow
= pRow
->mpNext
;
1128 mpLayout
->GetUpdatesManager().OnStartChanges();
1132 // allow user adjusting pane vs. client-area space, for upper-handle
1134 if ( mpPane
->IsHorizontal() )
1136 clientSize
= mpLayout
->GetClientHeight();
1138 clientSize
= mpLayout
->GetClientWidth();
1140 if ( forUpperHandle
&& ofs
< -clientSize
)
1142 int needed
= -(ofs
+ clientSize
);
1144 cbRowInfo
* pRow
= mpPane
->GetRowList()[ 0 ];
1146 // start squeezing rows from the top row towards bottom
1148 while( pRow
!= pTheRow
&& needed
)
1150 // only not-fixed rows can be squeezed
1152 if ( !pRow
->mHasOnlyFixedBars
)
1154 int prevHeight
= pRow
->mRowHeight
;
1156 int newHeight
= wxMax( event
.mpPane
->GetMinimalRowHeight( pRow
),
1157 prevHeight
- needed
);
1159 if ( newHeight
!= prevHeight
)
1161 event
.mpPane
->SetRowHeight( pRow
, newHeight
);
1163 needed
-= prevHeight
- pRow
->mRowHeight
;
1167 pRow
= pRow
->mpNext
;
1171 // allow user adjusting pane vs. client-area space, for lower-handle
1173 if ( !forUpperHandle
&& ofs
> clientSize
)
1175 int needed
= ofs
- clientSize
;
1177 cbRowInfo
* pRow
= mpPane
->GetRowList()[ mpPane
->GetRowList().Count() - 1 ];
1179 // start squeezing rows from the bottom towards the top row
1181 while( pRow
&& needed
)
1183 // only not-fixed rows can be squeezed
1185 if ( !pRow
->mHasOnlyFixedBars
)
1187 int prevHeight
= pRow
->mRowHeight
;
1189 int newHeight
= wxMax( event
.mpPane
->GetMinimalRowHeight( pRow
),
1190 prevHeight
- needed
);
1192 if ( newHeight
!= prevHeight
)
1194 event
.mpPane
->SetRowHeight( pRow
, newHeight
);
1196 needed
-= prevHeight
- pRow
->mRowHeight
;
1200 pRow
= pRow
->mpPrev
;
1204 if ( forUpperHandle
)
1206 event
.mpPane
->SetRowHeight( pTheRow
, pTheRow
->mRowHeight
+ (-ofs
) );
1208 event
.mpPane
->SetRowHeight( pTheRow
, pTheRow
->mRowHeight
+ ofs
);
1210 mpLayout
->RecalcLayout(FALSE
);
1212 mpLayout
->GetUpdatesManager().OnFinishChanges();
1213 mpLayout
->GetUpdatesManager().UpdateNow();