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;
134 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
136 if ( !pRow
->mBars
[i
]->IsFixed() )
137 pcntSum
+= pRow
->mBars
[i
]->mLenRatio
;
144 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
146 cbBarInfo
& bar
= *pRow
->mBars
[i
];
148 if ( !bar
.IsFixed() )
150 bar
.mLenRatio
= bar
.mLenRatio
/(pcntSum
);
154 wxMax( mpPane
->mProps
.mMinCBarDim
.x
, int( freeSpc
*bar
.mLenRatio
) );
157 bar
.mBounds
.x
= curX
;
158 curX
= bar
.mBounds
.x
+ bar
.mBounds
.width
;
162 void cbRowLayoutPlugin::AdjustLengthOfInserted( cbRowInfo
* pRow
, cbBarInfo
* pTheBar
)
166 // pTheBar is not-fixed
169 // FIXME:: what is this for??
176 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
178 if ( !pRow
->mBars
[i
]->IsFixed() )
179 totalLen
+= pRow
->mBars
[i
]->mBounds
.width
;
182 double curWidth
= pTheBar
->mBounds
.width
;
184 if ( pRow
->mBars
.Count() )
186 pTheBar
->mBounds
.width
= int( mpPane
->mPaneWidth
* (curWidth
/ double(totalLen
)) );
190 double freeSpc
= (double)GetRowFreeSpace( pRow
);
192 double pcntSum
= 0.0;
195 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
197 if ( !pRow
->mBars
[i
]->IsFixed() )
198 pcntSum
+= pRow
->mBars
[i
]->mLenRatio
;
201 // if no longer "balanced", assume that `pTheBar' was previously
202 // removed from this row (kind of AI...)
204 if ( pcntSum
< 0.98 )
206 pTheBar
->mBounds
.width
= freeSpc
* (1.0 - pcntSum
);
210 void cbRowLayoutPlugin::FitBarsToRange( int from
, int till
,
211 cbBarInfo
* pTheBar
, cbRowInfo
* pRow
)
213 cbBarInfo
* pFromBar
= NULL
;
214 cbBarInfo
* pTillBar
= NULL
;
216 if ( pTheBar
->mBounds
.x
> from
)
218 // it's range from the left
219 pFromBar
= pRow
->mBars
[0];
224 pFromBar
= pTheBar
->mpNext
;
228 // calc free space in the range
230 cbBarInfo
* pBar
= pFromBar
;
231 int freeSpc
= till
-from
;
234 while( pBar
!= pTillBar
)
236 if ( pBar
->IsFixed() )
238 freeSpc
-= pBar
->mBounds
.width
;
240 pcntSum
+= pBar
->mLenRatio
;
245 // adjust not-fixed bar sizes in the range
249 while( pBar
!= pTillBar
)
251 if ( !pBar
->IsFixed() )
253 pBar
->mBounds
.width
=
255 wxMax( mpPane
->mProps
.mMinCBarDim
.x
,
256 int( double(freeSpc
) * (pBar
->mLenRatio
/pcntSum
) )
262 // layout range, starting from the left-most bar
266 bool hasNotFixedBars
= FALSE
;
268 while ( pBar
!= pTillBar
)
270 wxRect
& bounds
= pBar
->mBounds
;
272 if ( !pBar
->IsFixed() )
274 hasNotFixedBars
= TRUE
;
276 freeSpc
-= bounds
.width
;
281 prevX
= bounds
.x
+ bounds
.width
;
286 // make width adjustment for the right-most bar in the range, due to
287 // lost precision when seting widths using f.p. length-ratios
289 if ( hasNotFixedBars
)
291 if ( pTheBar
->mBounds
.x
> from
)
293 if ( pTillBar
->mpPrev
)
295 wxRect
& tillBar
= pTillBar
->mpPrev
->mBounds
;
297 //tillBar.width = bar.mBounds.x - tillBar.x;
298 tillBar
.width
+= freeSpc
;
303 cbBarInfo
* pLast
= pRow
->mBars
[ pRow
->mBars
.Count() - 1 ];
305 if ( pLast
!= pTheBar
)
307 pTheBar
->mBounds
.width
+= freeSpc
;
309 SlideRightSideBars( pTheBar
);
315 void cbRowLayoutPlugin::MinimzeNotFixedBars( cbRowInfo
* pRow
, cbBarInfo
* pBarToPreserve
)
318 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
320 if ( !pRow
->mBars
[i
]->IsFixed() && pRow
->mBars
[i
] != pBarToPreserve
)
321 pRow
->mBars
[i
]->mBounds
.width
= mpPane
->mProps
.mMinCBarDim
.x
;
325 int cbRowLayoutPlugin::GetRowFreeSpace( cbRowInfo
* pRow
)
327 int freeSpc
= mpPane
->mPaneWidth
;
330 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
332 // not-fixed bars variable length, thus their
333 // dimensions are ignored
334 if ( pRow
->mBars
[i
]->IsFixed() )
335 freeSpc
-= pRow
->mBars
[i
]->mBounds
.width
;
341 void cbRowLayoutPlugin::RecalcLengthRatios( cbRowInfo
* pRow
)
343 double freeSpc
= double( GetRowFreeSpace( pRow
) );
345 cbBarInfo
* pBar
= pRow
->mBars
[0];
346 cbBarInfo
* pLastNotFixed
= NULL
;
348 double pcntLeft
= 1.0; // (100%)
350 #ifdef __EXPERIMENTAL
355 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
357 if ( !pRow
->mBars
[i
]->IsFixed() )
358 totalLen
+= pRow
->mBars
[i
]->mBounds
.width
;
363 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
365 cbBarInfo
& bar
= *pRow
->mBars
[i
];
367 if ( !bar
.IsFixed() )
370 #ifdef __EXPERIMENTAL
372 bar
.mLenRatio
= double(bar
.mBounds
.width
)/double(totalLen
);
374 bar
.mLenRatio
= double(bar
.mBounds
.width
)/freeSpc
;
377 pcntLeft
-= bar
.mLenRatio
;
378 pLastNotFixed
= pBar
;
382 // attach remainder (the result of lost precision) to the
383 // last not-fixed bar
385 #if !defined(__EXPERIMENTAL)
389 pLastNotFixed
->mLenRatio
+= pcntLeft
;
394 void cbRowLayoutPlugin::ApplyLengthRatios( cbRowInfo
* pRow
)
398 // FOR NOW:: all-in-one
401 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
403 if ( !pRow
->mBars
[i
]->IsFixed() )
404 pcntSum
+= pRow
->mBars
[i
]->mLenRatio
;
408 pBar = node_to_first_bar_node( pRow );
412 cbBarInfo& bar = node_to_bar( pBar );
414 if ( !bar.IsFixed() )
416 bar.mLenRatio = pcntSum / bar.mLenRatio;
423 double freeSpc
= GetRowFreeSpace( pRow
);
425 // tricky stuff (improtant!):
426 // when not-fixed bar is removed from the row and there are
427 // still some other not-fixed ones left in that row, then
428 // the sum of mLenRatio's is no longer 1.0 - this is left
429 // intintionally to handle the case when the removed bar
430 // is returned right back to the row - so that it would retain
431 // it's original dimensions in this row (this is kind of AI...)
433 // The problem is - when it's remvoed, the sum of
434 // mLenRatio's is not in "balance", i.e. is < 1.0,
435 // it's possible to restore balance, but instead of that
436 // we artifically ajdust freeSpc value in a way that it would
437 // look like total of mLetRatio's is 1.0, thus original
438 // len. ratios are _preserved_:
440 double unit
= freeSpc
/ pcntSum
;
442 bool haveSquished
= FALSE
;
444 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
446 if ( !pRow
->mBars
[i
]->IsFixed() )
448 cbBarInfo
& bar
= *pRow
->mBars
[i
];
450 if ( int( unit
* bar
.mLenRatio
) < mpPane
->mProps
.mMinCBarDim
.x
)
454 bar
.mBounds
.width
= -1; // mark as "squished"
456 pcntSum
-= bar
.mLenRatio
;
458 freeSpc
-= mpPane
->mProps
.mMinCBarDim
.x
;
465 unit
= freeSpc
/ pcntSum
;
467 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
469 cbBarInfo
& bar
= *pRow
->mBars
[i
];
471 bar
.mBounds
.x
= prevX
;
473 if ( !bar
.IsFixed() )
475 if ( bar
.mBounds
.width
== -1 )
477 bar
.mBounds
.width
= mpPane
->mProps
.mMinCBarDim
.x
;
479 bar
.mBounds
.width
= int( unit
* bar
.mLenRatio
);
481 // a little bit of AI:
482 // memorize bar's height and width, when docked in
483 // the current orientation - by making the current
484 // dimensions to be "preffered" ones for this docking state
486 if ( !bar
.IsFixed() )
488 bar
.mDimInfo
.mSizes
[ bar
.mState
].x
= bar
.mBounds
.width
;
489 bar
.mDimInfo
.mSizes
[ bar
.mState
].y
= bar
.mBounds
.height
;
493 prevX
= bar
.mBounds
.x
+ bar
.mBounds
.width
;
497 void cbRowLayoutPlugin::DetectBarHandles( cbRowInfo
* pRow
)
499 // first pass from left to right (detect left-side handles)
501 bool foundNotFixed
= FALSE
;
504 for( i
= 0; i
!= pRow
->mBars
.Count(); ++i
)
506 cbBarInfo
& bar
= *pRow
->mBars
[i
];
508 bar
.mHasLeftHandle
= FALSE
;
510 if ( !bar
.IsFixed() )
515 bar
.mpPrev
->IsFixed() )
517 bar
.mHasLeftHandle
= TRUE
;
519 foundNotFixed
= TRUE
;
523 // pass from right to left (detect right-side handles)
525 foundNotFixed
= FALSE
;
527 cbBarInfo
* pBar
= pRow
->mBars
[ pRow
->mBars
.Count() - 1 ];
531 pBar
->mHasRightHandle
= FALSE
;
533 if ( !pBar
->IsFixed() )
539 pBar
->mHasRightHandle
= TRUE
;
541 foundNotFixed
= TRUE
;
548 void cbRowLayoutPlugin::RelayoutNotFixedBarsAround( cbBarInfo
* pTheBar
, cbRowInfo
* pRow
)
550 if ( !pTheBar
->mpPrev
)
552 if ( !pTheBar
->IsFixed() )
554 // this bar the first in the row, move it's
555 // left edge to the very left
556 pTheBar
->mBounds
.width
+= pTheBar
->mBounds
.x
;
557 pTheBar
->mBounds
.x
= 0;
561 FitBarsToRange( 0, pTheBar
->mBounds
.x
, pTheBar
, pRow
);
563 if ( !pTheBar
->mpNext
)
565 if ( !pTheBar
->IsFixed() )
567 // this bar is the last one, move it's
568 // right edge to the very right
570 pTheBar
->mBounds
.width
= mpPane
->mPaneWidth
- pTheBar
->mBounds
.x
;
574 FitBarsToRange( pTheBar
->mBounds
.x
+ pTheBar
->mBounds
.width
, mpPane
->mPaneWidth
,
579 void cbRowLayoutPlugin::LayoutItemsVertically( cbRowInfo
& row
)
582 for( i
= 0; i
!= row
.mBars
.Count(); ++i
)
584 cbBarInfo
& bar
= *row
.mBars
[i
];
586 bar
.mBounds
.y
= row
.mRowY
;
588 if ( !bar
.IsFixed() )
590 // make all not-fixed bars of equal height
591 bar
.mBounds
.height
= row
.mRowHeight
;
593 if ( row
.mHasUpperHandle
)
595 bar
.mBounds
.y
+= mpPane
->mProps
.mResizeHandleSize
;
599 int cbRowLayoutPlugin::CalcRowHeight( cbRowInfo
& row
)
604 for( i
= 0; i
!= row
.mBars
.Count(); ++i
)
606 maxHeight
= wxMax( maxHeight
, row
.mBars
[i
]->mBounds
.height
);
611 void cbRowLayoutPlugin::StickRightSideBars( cbBarInfo
* pToBar
)
613 cbBarInfo
* pBar
= pToBar
->mpNext
;
614 cbBarInfo
* pPrev
= pToBar
;
618 wxRect
& cur
= pBar
->mBounds
;
619 wxRect
& prev
= pPrev
->mBounds
;
621 cur
.x
= prev
.x
+ prev
.width
;
628 void cbRowLayoutPlugin::SlideLeftSideBars( cbBarInfo
* pTheBar
)
630 // shift left-side-bars to the left (with respect to "theBar"),
631 // so that they would not obscured by each other
633 cbBarInfo
* pBar
= pTheBar
->mpPrev
;
634 cbBarInfo
* pPrev
= pTheBar
;
638 wxRect
& cur
= pBar
->mBounds
;
639 wxRect
& prev
= pPrev
->mBounds
;
641 if ( cur
.x
+ cur
.width
> prev
.x
)
643 cur
.x
= prev
.x
- cur
.width
;
650 void cbRowLayoutPlugin::SlideRightSideBars( cbBarInfo
* pTheBar
)
652 // shift right-side-bars to the right (with respect to "theBar"),
653 // so that they would not be obscured by each other
655 cbBarInfo
* pBar
= pTheBar
->mpNext
;
656 cbBarInfo
* pPrev
= pTheBar
;
660 wxRect
& cur
= pBar
->mBounds
;
661 wxRect
& prev
= pPrev
->mBounds
;
663 if ( cur
.x
< prev
.x
+ prev
.width
)
665 cur
.x
= prev
.x
+ prev
.width
;
672 void cbRowLayoutPlugin::ShiftLeftTrashold( cbBarInfo
* pTheBar
, cbRowInfo
& row
)
674 wxRect
& first
= row
.mBars
[0]->mBounds
;
678 row
.mBars
[0]->mBounds
.x
= 0;
680 SlideRightSideBars( row
.mBars
[0] );
684 void cbRowLayoutPlugin::ShiftRightTrashold( cbBarInfo
* pTheBar
, cbRowInfo
& row
)
686 wxRect
& theBar
= pTheBar
->mBounds
;
690 cbBarInfo
* pBar
= pTheBar
;
692 // calculate free spece on the left side
698 wxRect
& cur
= pBar
->mBounds
;
702 wxRect
& prev
= pBar
->mpPrev
->mBounds
;
704 leftFreeSpc
+= cur
.x
- prev
.x
- prev
.width
;
707 leftFreeSpc
+= cur
.x
;
720 int rightOverflow
= 0;
722 if ( pTheBar
->IsFixed() )
728 wxRect
& cur
= pBar
->mBounds
;
730 if ( cur
.x
+ cur
.width
> mpPane
->mPaneWidth
)
732 rightOverflow
= cur
.x
+ cur
.width
- mpPane
->mPaneWidth
;
738 if ( rightOverflow
> 0 )
740 if ( leftFreeSpc
<= 0 ) return;
742 if ( pTheBar
->mpNext
)
744 wxRect
& next
= pTheBar
->mpNext
->mBounds
;
746 // if there's enough space on the left, move over one half-obscured
747 // bar from the right to the left side with respect to "theBar"
749 if ( next
.width
< leftFreeSpc
)
751 cbBarInfo
* pNext
= pTheBar
->mpNext
;
753 row
.mBars
.Remove( pNext
);
755 row
.mBars
.Insert( pNext
, row
.mBars
.Index( pTheBar
) );
757 next
.x
= theBar
.x
- next
.width
;
759 // re-setup mpPrev/mpNext references after insertion
761 mpPane
->InitLinksForRow( &row
);
765 StickRightSideBars( pTheBar
);
766 SlideLeftSideBars ( pTheBar
);
772 int leftShift
= ( rightOverflow
> leftFreeSpc
)
776 theBar
.x
-= leftShift
;
778 StickRightSideBars( pTheBar
);
779 SlideLeftSideBars ( pTheBar
);
783 } // end of if ( rightOverflow )
790 void cbRowLayoutPlugin::InsertBefore( cbBarInfo
* pBeforeBar
,
796 row
.mBars
.Insert( pTheBar
, row
.mBars
.Index( pBeforeBar
) );
798 row
.mBars
.Add( pTheBar
);
800 pTheBar
->mpRow
= &row
;
803 void cbRowLayoutPlugin::DoInsertBar( cbBarInfo
* pTheBar
, cbRowInfo
& row
)
805 wxRect
& theBar
= pTheBar
->mBounds
;
808 if ( theBar.x < 0 && !node_to_bar( pTheBar ).IsFixed() )
811 theBar.width += theBar.x;
816 for( i
= 0; i
!= row
.mBars
.Count(); ++i
)
818 cbBarInfo
& bar
= *row
.mBars
[i
];
820 wxRect
& cur
= bar
.mBounds
;
822 // if bar hits the left edge
823 if ( theBar
.x
<= cur
.x
)
825 InsertBefore( &bar
, pTheBar
, row
);
830 // if bar hits the right edge
831 if ( theBar
.x
<= cur
.x
+ cur
.width
)
833 if ( theBar
.x
+ theBar
.width
> cur
.x
+ cur
.width
)
835 InsertBefore( bar
.mpNext
, pTheBar
, row
);
839 // otherwise the bar lies within the bounds of current bar
841 int leftDist
= theBar
.x
- cur
.x
;
842 int rightDist
= cur
.x
+ cur
.width
- (theBar
.x
+ theBar
.width
);
844 if ( leftDist
< rightDist
)
846 InsertBefore( &bar
, pTheBar
, row
);
848 InsertBefore( bar
.mpNext
, pTheBar
, row
);
854 InsertBefore( NULL
, pTheBar
, row
); // insert at the end
859 void cbRowLayoutPlugin::OnInsertBar( cbInsertBarEvent
& event
)
861 cbBarInfo
* pBarToInsert
= event
.mpBar
;
862 cbRowInfo
* pIntoRow
= event
.mpRow
;
863 mpPane
= event
.mpPane
;
865 if ( !pBarToInsert
->IsFixed() )
867 AdjustLengthOfInserted( pIntoRow
, pBarToInsert
);
869 DoInsertBar( pBarToInsert
, *pIntoRow
);
871 mpPane
->InitLinksForRow( pIntoRow
); // relink "mpNext/mpPrev"s
873 // perform relayouting of the bars after insertion
875 // init bar location info
876 pBarToInsert
->mAlignment
= event
.mpPane
->mAlignment
;
877 pBarToInsert
->mRowNo
= event
.mpPane
->GetRowIndex( pIntoRow
);
879 #ifdef __EXPERIMENTAL
881 if ( !pIntoRow
->mHasOnlyFixedBars
|| !pBarToInsert
->IsFixed() )
883 RecalcLengthRatios( pIntoRow
);
887 MinimzeNotFixedBars( pIntoRow
, pBarToInsert
);
889 SlideLeftSideBars ( pBarToInsert
);
890 SlideRightSideBars( pBarToInsert
);
892 ShiftLeftTrashold ( pBarToInsert
, *pIntoRow
);
893 ShiftRightTrashold( pBarToInsert
, *pIntoRow
);
895 mpPane
->SyncRowFlags( pIntoRow
);
897 CheckIfAtTheBoundary( pBarToInsert
, *pIntoRow
);
899 if ( event
.mpPane
->IsHorizontal() )
901 pBarToInsert
->mState
= wxCBAR_DOCKED_HORIZONTALLY
;
903 pBarToInsert
->mState
= wxCBAR_DOCKED_VERTICALLY
;
905 if ( !pIntoRow
->mHasOnlyFixedBars
)
908 #ifdef __EXPERIMENTAL
910 ExpandNotFixedBars( pIntoRow
);
913 RelayoutNotFixedBarsAround( pBarToInsert
, pIntoRow
);
914 RecalcLengthRatios( pIntoRow
);
918 DetectBarHandles( pIntoRow
);
920 // do proportional resizing of not-fixed bars
921 ApplyLengthRatios( pIntoRow
);
924 // adjust the bar's docking state
926 // a little bit of AI:
927 // memorize bar's height and width, when docked in
928 // the current orientation - by making the current
929 // dimensions to be "preferred" ones for this docking state
931 if ( !pBarToInsert
->IsFixed() )
933 cbBarInfo
& bar
= *pBarToInsert
;
935 bar
.mDimInfo
.mSizes
[ bar
.mState
].x
= bar
.mBounds
.width
;
936 bar
.mDimInfo
.mSizes
[ bar
.mState
].y
= bar
.mBounds
.height
;
940 void cbRowLayoutPlugin::OnRemoveBar ( cbRemoveBarEvent
& event
)
942 cbBarInfo
* pBar
= event
.mpBar
;
943 mpPane
= event
.mpPane
;
945 cbRowInfo
* pRow
= pBar
->mpRow
;
947 mpLayout
->GetUpdatesManager().OnBarWillChange( pBar
, pRow
, event
.mpPane
);
949 // invalidate the whole row
950 //pFirst->mpRowInfo->mMgrData.mPrevBounds.x = -1;
952 pRow
->mBars
.Remove( pBar
);
954 // rest bar information after removing it from the row
956 pBar
->mHasLeftHandle
= FALSE
;
957 pBar
->mHasRightHandle
= FALSE
;
959 mpPane
->InitLinksForRow( pRow
); // relink "mpNext/mpPrev"s
961 if ( pRow
->mBars
.Count() == 0 )
963 // empty rows should not exist
965 event
.mpPane
->GetRowList().Remove( pRow
);
969 mpPane
->InitLinksForRows();
973 // force repainting of bars, in the row, from which the bar was removed
975 // FIXME:: really needed?
976 pRow
->mBars
[0]->mUMgrData
.SetDirty(TRUE
);
978 // re-setup mHasOnlyFixedBars flag for the row information
979 event
.mpPane
->SyncRowFlags( pRow
);
981 DetectBarHandles( pRow
);
983 if ( !pRow
->mHasOnlyFixedBars
)
985 ExpandNotFixedBars( pRow
);
989 void cbRowLayoutPlugin::OnLayoutRow( cbLayoutRowEvent
& event
)
991 cbRowInfo
* pRow
= event
.mpRow
;
992 mpPane
= event
.mpPane
;
994 MinimzeNotFixedBars( pRow
, NULL
);
996 if ( !pRow
->mHasOnlyFixedBars
)
998 // do proportional resizing of not-fixed bars
999 ApplyLengthRatios( pRow
);
1002 cbBarInfo
& lastBar
= *pRow
->mBars
[ pRow
->mBars
.Count() - 1 ];
1003 cbBarInfo
& firstBar
= *pRow
->mBars
[ 0 ];
1005 // FIXME:: Next line not used
1006 // wxRect& bounds = lastBar.mBounds;
1008 if ( lastBar
.mBounds
.x
+ lastBar
.mBounds
.width
> mpPane
->mPaneWidth
)
1010 lastBar
.mBounds
.x
= mpPane
->mPaneWidth
- lastBar
.mBounds
.width
;
1012 // first simulate left-row-edge friction
1014 SlideLeftSideBars( &lastBar
);
1016 if ( firstBar
.mBounds
.x
< 0 )
1017 firstBar
.mBounds
.x
= 0;
1019 // then left-row-edge function, though this
1020 // may cause some of the right-side bars going
1021 // out of row bounds, but left-side always
1022 // has the highest "priority"
1024 SlideRightSideBars( &firstBar
);
1027 event
.Skip(); // pass event to the next handler
1030 void cbRowLayoutPlugin::OnLayoutRows( cbLayoutRowsEvent
& event
)
1032 mpPane
= event
.mpPane
;
1036 // FIXME:: Next line not used.
1037 // RowArrayT& arr = mpPane->GetRowList();
1040 for( i
= 0; i
!= mpPane
->GetRowList().Count(); ++i
)
1042 cbRowInfo
& row
= *mpPane
->GetRowList()[ i
];
1044 // setup "has-handle" flags for rows, which depend on the existance
1045 // of not-fixed bars in the row
1047 if ( !row
.mHasOnlyFixedBars
)
1049 if ( mpPane
->mAlignment
== FL_ALIGN_TOP
||
1050 mpPane
->mAlignment
== FL_ALIGN_LEFT
)
1052 row
.mHasLowerHandle
= TRUE
;
1054 row
.mHasUpperHandle
= FALSE
;
1058 row
.mHasUpperHandle
= TRUE
;
1060 row
.mHasLowerHandle
= FALSE
;
1065 // otherwise, rows with fixed-bars only, have no height-resizing handles
1066 row
.mHasUpperHandle
= FALSE
;
1067 row
.mHasLowerHandle
= FALSE
;
1070 // setup vertical positions for items in the row
1074 row
.mRowWidth
= mpPane
->mPaneWidth
;
1075 row
.mRowHeight
= CalcRowHeight( row
);
1077 LayoutItemsVertically( row
);
1079 if ( row
.mHasUpperHandle
)
1080 row
.mRowHeight
+= mpPane
->mProps
.mResizeHandleSize
;
1081 if ( row
.mHasLowerHandle
)
1082 row
.mRowHeight
+= mpPane
->mProps
.mResizeHandleSize
;
1084 curY
+= row
.mRowHeight
;
1087 event
.Skip(); // pass event to the next handler - other hookeds plugin
1088 // may also add some "refinements" to the layout now
1091 void cbRowLayoutPlugin::OnResizeRow( cbResizeRowEvent
& event
)
1093 // extract resize-event info
1094 int ofs
= event
.mHandleOfs
;
1095 bool forUpperHandle
= event
.mForUpperHandle
;
1096 cbRowInfo
* pTheRow
= event
.mpRow
;
1097 mpPane
= event
.mpPane
;
1099 // FIXME:: Next line not used.
1100 //int newHeight = pTheRow->mRowHeight;
1104 if ( forUpperHandle
)
1106 // calculate available free space from above,
1107 // which can be obtained by squeezing not-fixed height rows
1109 cbRowInfo
* pRow
= pTheRow
->mpPrev
;
1113 freeSpc
+= pRow
->mRowHeight
- event
.mpPane
->GetMinimalRowHeight( pRow
);
1115 pRow
= pRow
->mpPrev
;
1120 // calculate available free space from below,
1121 // which can be obtained by squeezing not-fixed height rows
1123 cbRowInfo
* pRow
= pTheRow
->mpNext
;
1127 freeSpc
+= pRow
->mRowHeight
- mpPane
->GetMinimalRowHeight( pRow
);
1129 pRow
= pRow
->mpNext
;
1133 mpLayout
->GetUpdatesManager().OnStartChanges();
1137 // allow user adjusting pane vs. client-area space, for upper-handle
1139 if ( mpPane
->IsHorizontal() )
1141 clientSize
= mpLayout
->GetClientHeight();
1143 clientSize
= mpLayout
->GetClientWidth();
1145 if ( forUpperHandle
&& ofs
< -clientSize
)
1147 int needed
= -(ofs
+ clientSize
);
1149 cbRowInfo
* pRow
= mpPane
->GetRowList()[ 0 ];
1151 // start squeezing rows from the top row towards bottom
1153 while( pRow
!= pTheRow
&& needed
)
1155 // only not-fixed rows can be squeezed
1157 if ( !pRow
->mHasOnlyFixedBars
)
1159 int prevHeight
= pRow
->mRowHeight
;
1161 int newHeight
= wxMax( event
.mpPane
->GetMinimalRowHeight( pRow
),
1162 prevHeight
- needed
);
1164 if ( newHeight
!= prevHeight
)
1166 event
.mpPane
->SetRowHeight( pRow
, newHeight
);
1168 needed
-= prevHeight
- pRow
->mRowHeight
;
1172 pRow
= pRow
->mpNext
;
1176 // allow user adjusting pane vs. client-area space, for lower-handle
1178 if ( !forUpperHandle
&& ofs
> clientSize
)
1180 int needed
= ofs
- clientSize
;
1182 cbRowInfo
* pRow
= mpPane
->GetRowList()[ mpPane
->GetRowList().Count() - 1 ];
1184 // start squeezing rows from the bottom towards the top row
1186 while( pRow
&& needed
)
1188 // only not-fixed rows can be squeezed
1190 if ( !pRow
->mHasOnlyFixedBars
)
1192 int prevHeight
= pRow
->mRowHeight
;
1194 int newHeight
= wxMax( event
.mpPane
->GetMinimalRowHeight( pRow
),
1195 prevHeight
- needed
);
1197 if ( newHeight
!= prevHeight
)
1199 event
.mpPane
->SetRowHeight( pRow
, newHeight
);
1201 needed
-= prevHeight
- pRow
->mRowHeight
;
1205 pRow
= pRow
->mpPrev
;
1209 if ( forUpperHandle
)
1211 event
.mpPane
->SetRowHeight( pTheRow
, pTheRow
->mRowHeight
+ (-ofs
) );
1213 event
.mpPane
->SetRowHeight( pTheRow
, pTheRow
->mRowHeight
+ ofs
);
1215 mpLayout
->RecalcLayout(FALSE
);
1217 mpLayout
->GetUpdatesManager().OnFinishChanges();
1218 mpLayout
->GetUpdatesManager().UpdateNow();