📄 containers.cpp
字号:
//Containers.cpp/*Copyright 2000-2004 The VCF Project.Please see License.txt in the top level directorywhere you installed the VCF.*/#include "vcf/ApplicationKit/ApplicationKit.h"#include "vcf/ApplicationKit/AbstractContainer.h"#include "vcf/ApplicationKit/Containers.h"using namespace VCF;StandardContainer::StandardContainer(): bottomBorderHeight_(0.0), topBorderHeight_(0.0), rightBorderWidth_(0.0), leftBorderWidth_(0.0){}StandardContainer::StandardContainer( Component* owner ): AbstractContainer(owner), bottomBorderHeight_(0.0), topBorderHeight_(0.0), rightBorderWidth_(0.0), leftBorderWidth_(0.0){}void StandardContainer::resizeChildren( Control* control ){ Rect bounds = controlContainer_->getClientBounds(); if ( bounds.isEmpty() ) { //return; } bounds.left_ += leftBorderWidth_; bounds.top_ += topBorderHeight_; bounds.right_ -= rightBorderWidth_; bounds.bottom_ -= bottomBorderHeight_; bool controlJustAdded = false; if ( NULL != control ) { std::vector<Control*>::iterator found = std::find( controls_.begin(), controls_.end(), control ); controlJustAdded = ( found == controls_.end() ); } bool needAnchorWork = anchorWork() || (controlJustAdded && (control->getAlignment() == AlignNone) && (control->getAnchor() != 0)); bool needAlignWork = alignWork()|| (controlJustAdded && (control->getAlignment() != AlignNone)); if ( (true == needAnchorWork) || (true == needAlignWork) ) { controlContainer_->getPeer()->beginSetBounds( controls_.size() ); } if ( true == needAlignWork ){ alignFixed( control, controlJustAdded, AlignTop, &bounds ); alignFixed( control, controlJustAdded, AlignBottom, &bounds ); alignFixed( control, controlJustAdded, AlignLeft, &bounds ); alignFixed( control, controlJustAdded, AlignRight, &bounds ); alignFixed( control, controlJustAdded, AlignClient, &bounds ); } if ( true == needAnchorWork ) { doAnchors( control, controlJustAdded, &bounds ); } if ( (true == needAnchorWork) || (true == needAlignWork) ) { controlContainer_->getPeer()->endSetBounds(); }}void StandardContainer::alignFixed( Control* initialControl, const bool& controlJustAdded, const AlignmentType& alignment, Rect* rect ){ std::vector< Control* > alignmentList; std::vector< Control* >::iterator it = controls_.begin(); ulong32 index=0; while ( it != controls_.end() ){ Control* child = *it; if ( (child->getAlignment() == alignment) && (child->getVisible()) && !child->isIgnoredForLayout() ){ alignmentList.push_back( child ); } it ++; } if ( NULL != initialControl ) { if ( (initialControl->getVisible()) && (initialControl->getAlignment() == alignment) && !initialControl->isIgnoredForLayout() ) { alignmentList.push_back( initialControl ); } } if ( (alignment == AlignBottom) || (alignment == AlignRight) ) { std::reverse( alignmentList.begin(), alignmentList.end() ); } it = alignmentList.begin(); while ( it != alignmentList.end() ) { doPosition( *it, alignment, rect ); it ++; }}bool StandardContainer::insertBefore( Control* initialControl, const bool& controlJustAdded, Control* c1, Control* c2, const AlignmentType& alignment, Rect* bounds ){ bool result = false; Rect bounds1; Rect bounds2; if ( (NULL != c1) && (NULL != c2) ){ bounds1 = c1->getBounds(); bounds2 = c2->getBounds(); if ( controlJustAdded ) { //first time through //adjust the bounds if neccessary by the difference from 0 to bounds->topleft if ( initialControl == c1 ) { bounds1.offset( bounds->left_, bounds->top_ ); } else if ( initialControl == c2 ) { bounds2.offset( bounds->left_, bounds->top_ ); } } switch ( alignment ){ case AlignTop:{ result = bounds1.top_ < bounds2.top_; } break; case AlignBottom:{ //this ->> (bounds1.top_ /*+ bounds1.getHeight()*/) //is wrong - commented out to fix [ 532623 ] alignment problem & [ 525214 ] alignment loss after resize JEC 20-03-2002 result = (bounds1.top_ + bounds1.getHeight()) > (bounds2.top_ + bounds2.getHeight()); } break; case AlignLeft:{ result = bounds1.left_ < bounds2.left_; } break; case AlignRight:{ //this ->> (bounds1.top_ /*+ bounds1.getHeight()*/) //is wrong - commented out to fix [ 532623 ] alignment problem & [ 525214 ] alignment loss after resize JEC 20-03-2002 result = (bounds1.left_ + bounds1.getWidth()) > (bounds2.left_ + bounds2.getWidth()); } break; } } return result;}/***the rect parameter is the available bounds for the parent control that is being adjusted*as each of the child controls repositions itself*/void StandardContainer::doPosition( Control* component, const AlignmentType& alignment, Rect* rect ){ Rect componentBounds = component->getBounds(); double w = componentBounds.getWidth(); double h = componentBounds.getHeight(); switch ( alignment ){ case AlignLeft:{ rect->left_ = rect->left_ + w;//minVal<>( rect->left_ + w, rect->right_ ); } break; case AlignTop:{ rect->top_ = rect->top_ + h;//minVal<>( rect->bottom_, rect->top_ + h ); } break; case AlignRight:{ rect->right_ = rect->right_ - w;//maxVal<>(rect->left_, rect->right_ - w);//VCF::maxVal<double>( rect->right_ - w, rect->left_ ); } break; case AlignBottom:{ rect->bottom_ = rect->bottom_- h;//maxVal<>( rect->bottom_- h, rect->top_);//VCF::maxVal<double>( rect->bottom_ - h, rect->top_ ); } break; } switch ( alignment ){ case AlignLeft:{ componentBounds.left_ = rect->left_ - w;//VCF::maxVal<double>( 0.0, rect->left_ - w ); componentBounds.top_ = rect->top_; componentBounds.right_ = componentBounds.left_ + w; componentBounds.bottom_ = componentBounds.top_; if ( (rect->bottom_ - rect->top_) >= 0 ) { componentBounds.bottom_ += rect->bottom_ - rect->top_; } else { componentBounds.bottom_ += h; } component->setBounds( &componentBounds ); } break; case AlignTop:{ componentBounds.left_ = rect->left_; componentBounds.top_ = rect->top_ - h;//VCF::maxVal<double>( 0.0, rect->top_ - h ); componentBounds.right_ = componentBounds.left_; if ( (rect->right_ - rect->left_) >= 0 ) { componentBounds.right_ += (rect->right_ - rect->left_); } else { componentBounds.right_ += w; } componentBounds.bottom_ = componentBounds.top_ + h; component->setBounds( &componentBounds ); } break; case AlignRight:{ componentBounds.left_ = rect->right_; componentBounds.top_ = rect->top_; componentBounds.right_ = rect->right_ + w; componentBounds.bottom_ = componentBounds.top_; componentBounds.bottom_ = componentBounds.top_; if ( (rect->bottom_ - rect->top_) >= 0 ) { componentBounds.bottom_ += rect->bottom_ - rect->top_; } else { componentBounds.bottom_ += h; } component->setBounds( &componentBounds ); } break; case AlignBottom:{ componentBounds.left_ = rect->left_; componentBounds.top_ = rect->bottom_; componentBounds.right_ = componentBounds.left_; if ( (rect->right_ - rect->left_) >= 0 ) { componentBounds.right_ += (rect->right_ - rect->left_); } else { componentBounds.right_ += w; } componentBounds.bottom_ = componentBounds.top_ + h; component->setBounds( &componentBounds ); } break; case AlignClient:{ Rect clientBounds; clientBounds.setRect( maxVal<>(0.0,rect->left_),maxVal<>(0.0,rect->top_), maxVal<>(0.0,rect->right_),maxVal<>(0.0,rect->bottom_) ); component->setBounds( &clientBounds ); } break; }}void StandardContainer::doAlign( Control* initialControl, const bool& controlJustAdded, const AlignmentType& alignment, Rect* rect ){ std::vector< Control* > alignmentList; if ( NULL != initialControl ) { if ( (initialControl->getVisible()) && (initialControl->getAlignment() == alignment) && !initialControl->isIgnoredForLayout() ) { alignmentList.push_back( initialControl ); } } std::vector< Control* >::iterator it = controls_.begin(); ulong32 index=0; while ( it != controls_.end() ){ Control* child = *it; if ( (child->getAlignment() == alignment) && (child->getVisible()) && !child->isIgnoredForLayout() ){ ulong32 insertIndex = 0; if ( NULL != initialControl && initialControl == child ) { it ++; index ++; continue; } while ( (insertIndex < alignmentList.size()) && !insertBefore( initialControl, controlJustAdded, child, alignmentList[insertIndex], alignment, rect ) ){ insertIndex++; } alignmentList.insert( alignmentList.begin() + insertIndex, child ); } it ++; index ++; } it = alignmentList.begin(); while ( it != alignmentList.end() ) { doPosition( *it, alignment, rect ); it ++; }}bool StandardContainer::alignWork(){ bool result = false; std::vector<Control*>::iterator it = controls_.begin(); while ( it != controls_.end() ) { if ( (*it)->getAlignment() != AlignNone && !(*it)->isIgnoredForLayout() ){ result = true; break; } it ++; } return result;}bool StandardContainer::anchorWork(){ bool result = false; std::vector<Control*>::iterator it = controls_.begin(); while ( it != controls_.end() ) { if ( AnchorNone != (*it)->getAnchor() && !(*it)->isIgnoredForLayout() ) { result = true; break; } it ++; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -