⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 control.cpp

📁 这是VCF框架的代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//Control.cpp/*Copyright 2000-2004 The VCF Project.Please see License.txt in the top level directorywhere you installed the VCF.*//* Generated by Together */#include "vcf/ApplicationKit/ApplicationKit.h"#include "vcf/ApplicationKit/Action.h"#include "vcf/ApplicationKit/ActionEvent.h"using namespace VCF;Control* Control::capturedMouseControl = NULL;Control* Control::currentFocusedControl = NULL;Control* Control::previousMouseOverControl = NULL;Control::Control():	peer_(NULL),	context_(NULL),	parent_(NULL),	aligment_(AlignNone),	anchor_(AnchorNone),	bounds_(NULL),	clientBounds_(NULL),	border_(NULL),	color_(NULL),	font_(NULL),	view_(NULL),	popupMenu_(NULL),	scrollable_(NULL),	cursorID_(0),	cursor_(NULL),	tabOrder_(-1),	container_(NULL),	controlState_(Control::csDefaultControlState){	//this (Font) cast is to avoid an internal compiler error on some vc6 versions	font_ = new Font( (Font) UIToolkit::getUIMetricsManager()->getDefaultFontFor( UIMetricsManager::ftControlFont ) );	context_ = new ControlGraphicsContext( this );	bounds_ = new Rect();	clientBounds_ = new Rect();	color_ = new Color;	setCursorID( (long)Cursor::SCT_DEFAULT );	setColor( GraphicsToolkit::getSystemColor( SYSCOLOR_FACE ) );	viewControl_ = this;	anchorDeltas_[ANCHOR_DTOP] = 0.0f;	anchorDeltas_[ANCHOR_DLEFT] = 0.0f;	anchorDeltas_[ANCHOR_DBOTTOM] = 0.0f;	anchorDeltas_[ANCHOR_DRIGHT] = 0.0f;	minSize_.width_ = Control::mmIgnoreMinWidth;	minSize_.height_ = Control::mmIgnoreMinHeight;	maxSize_.width_ = Control::mmIgnoreMaxWidth;	maxSize_.height_ = Control::mmIgnoreMaxHeight;}Control::~Control(){	componentState_ = Component::csDestroying;	/**	this shouldn't happen, but it's	possible if an exception is thrown in a constructor	and not handled. In this case the Control::destroy	method will not be called, but rather the destructor	will be called directly.	So we double check here and delete the control peer	*/	if ( NULL != peer_ ) {		peer_->setControl( NULL );		peer_->destroyControl();		delete peer_;		peer_ = NULL;	}}void Control::destroy(){		if ( isLightWeight() ) {		//have to handle a Component::COMPONENT_DESTROYED event manually		//as they will NOT recv notification from the underlying windowing system		VCF::ComponentEvent event( this, Component::COMPONENT_DESTROYED );		handleEvent( &event );	}	if ( NULL != peer_ ) {		UIToolkit::removeAcceleratorKeysForControl( this );	}	if ( this == Control::previousMouseOverControl ) {		Control::previousMouseOverControl = NULL;	}	delete bounds_;	bounds_ = NULL;	delete clientBounds_;	clientBounds_ = NULL;	delete color_;	color_ = NULL;	delete context_;	context_ = NULL;	if ( NULL != peer_ ) {		peer_->destroyControl();		delete peer_;		peer_ = NULL;	}	if ( NULL != font_ ){		font_->free();		font_ = NULL;	}	if ( this == Control::currentFocusedControl ) {		Control::currentFocusedControl = NULL;	}	if ( NULL != view_ ) {		Object* obj = dynamic_cast<Object*>( view_ );		if ( NULL != obj ) {			obj->release();		}		else {			delete view_;		}	}	view_ = NULL;		container_ = NULL;		Component::destroy();}Border* Control::getBorder(){	return border_;}void Control::setBorder( Border* border ){		border_ = border;	if ( NULL != border_ ) {		if ( NULL == border_->getOwner() ) {			addComponent( border_ );		}	}		peer_->setBorder( border_ );}Rect Control::getBounds()/**throw( InvalidPeer ); -JEC - FIXME later*/{		Control* parent = getParent();	bool lightweightParent = false;	if ( NULL != parent ) {		lightweightParent = parent->isLightWeight();	}	if ( lightweightParent && !isLightWeight() ) {		*bounds_ = peer_->getBounds();		Rect tmpBounds = *bounds_;		tmpBounds.offset( -tmpBounds.left_, -tmpBounds.top_ );		translateToScreenCoords( &tmpBounds );		parent->translateFromScreenCoords( &tmpBounds );		*bounds_ =  tmpBounds;	}	else {		*bounds_ = peer_->getBounds();		//peer_->setBounds( bounds_ );	}	return *bounds_;}Rect Control::getClientBounds( const bool& includeBorder ) /**throw( InvalidPeer ); -JEC - FIXME later*/{		Rect r = peer_->getBounds();	clientBounds_->setRect( 0.0, 0.0, r.getWidth(), r.getHeight() );	if ( (includeBorder) && (NULL != border_) ){		r = *clientBounds_;		*clientBounds_ = border_->getClientRect( &r, this );	}	return *clientBounds_;}double Control::getLeft() /**throw( InvalidPeer ); -JEC - FIXME later*/{		//*bounds_ = peer_->getBounds();	getBounds();	return bounds_->left_;}double Control::getRight(){	getBounds();	//*bounds_ = peer_->getBounds();	return bounds_->right_;}double Control::getBottom() /**throw( InvalidPeer ); -JEC - FIXME later*/{	getBounds();	//*bounds_ = peer_->getBounds();	return bounds_->bottom_;}double Control::getWidth() /**throw( InvalidPeer ); -JEC - FIXME later*/{	getBounds();	//*bounds_ = peer_->getBounds();	return bounds_->getWidth();}double Control::getTop() /**throw( InvalidPeer ); -JEC - FIXME later*/{	getBounds();	//*bounds_ = peer_->getBounds();	return bounds_->top_;}double Control::getHeight() /**throw( InvalidPeer ); -JEC - FIXME later*/{	//double result = 0.0;	getBounds();	//*bounds_ = peer_->getBounds();	//result = bounds_->getHeight();	return bounds_->getHeight();}bool Control::getVisible() /**throw( InvalidPeer ); -JEC - FIXME later*/{	return (controlState_ & Control::csVisible) ? true : false;//peer_->getVisible();}AlignmentType Control::getAlignment(){	return aligment_;}bool Control::isIgnoredForLayout(){	return (controlState_ & Control::csIgnoreForLayout) ? true : false;}void Control::setIgnoredForLayout( const bool& val ){	if ( val ) {		controlState_ |= Control::csIgnoreForLayout;	}	else {		controlState_ &= ~Control::csIgnoreForLayout;	}	Control* parent = getParent();	if ( NULL != parent ) {		parent->getContainer()->resizeChildren( NULL );	}}void Control::setBounds( const double& x, const double& y, const double& width, const double& height ){	setBounds( &Rect( x, y, x+width, y+height ) );}void Control::setBounds( Rect* rect, const bool& anchorDeltasNeedUpdating ) /**throw( InvalidPeer ); -JEC - FIXME later*/{	*bounds_ = *rect;	/**	Adjust the bounds to take into account a	potentially lightweight parent	*/	Control* parent = getParent();	bool lightweightParent = false;	if ( NULL != parent ) {		lightweightParent = parent->isLightWeight();	}	if ( lightweightParent && !isLightWeight() ) {		Control* realParent = parent;		while ( NULL != realParent ) {			if ( !realParent->isLightWeight() ) {				break;			}			realParent = realParent->getParent();		}		if ( NULL != realParent ) {			Rect tmp = *bounds_;			Rect tmp2 = *bounds_;			tmp.offset( -tmp.left_, -tmp.top_ );			parent->translateToScreenCoords( &tmp );			realParent->translateFromScreenCoords( &tmp );			tmp2.offset( tmp.left_, tmp.top_ );			*bounds_ = tmp2;			peer_->setBounds( &tmp2 );		}		else {			peer_->setBounds( bounds_ );		}	}	else {		peer_->setBounds( bounds_ );	}	if ( isUsingRenderBuffer() ) {		if ( NULL == context_->getDrawingArea() ) {			context_->setDrawingArea( *bounds_ );		}	}	if ( true == anchorDeltasNeedUpdating ) {		updateAnchorDeltas();	}	//check to see if we need to adjust the scrollable's virtual height/width	//of our parent	if ( (getAlignment() == AlignNone) && (!ignoreForParentScrolling()) ) {		Control* parent = getParent();		if ( NULL != parent ) {			Container* container = parent->getContainer();			Scrollable* scrollable = parent->getScrollable();			if ( (NULL != container) && (NULL != scrollable) ) {				Rect r = getBounds();				if ( scrollable->getVirtualViewHeight() < r.bottom_ ) {					scrollable->setVirtualViewHeight( r.bottom_ );				}				if ( scrollable->getVirtualViewWidth() < r.right_ ) {					scrollable->setVirtualViewWidth( r.right_ );				}			}		}	}}void Control::setAlignment( const AlignmentType& alignment ){	aligment_ = alignment;	/**	Fix submitted by Marcello - see bug [ 789945 ] Control::setAlignment() does not allow only one align style	*/	if ( aligment_ != AlignNone ) {		anchor_ = AnchorNone;	}	Control* parent = getParent();	if ( NULL != parent ){		Container* container = parent->getContainer();		if ( NULL != container ){			container->resizeChildren(NULL);//this);		}	}	updateAnchorDeltas();}void Control::setLeft( const double& left ) /**throw( InvalidPeer ); -JEC - FIXME later*/{	double dx = bounds_->getWidth();	bounds_->left_ = left;	bounds_->right_ = left + dx;	setBounds( bounds_ );}void Control::setRight( const double& right ) /**throw( InvalidPeer ); -JEC - FIXME later*/{	bounds_->right_ = right;	setBounds( bounds_ );}void Control::setWidth( const double& width ) /**throw( InvalidPeer ); -JEC - FIXME later*/{	bounds_->right_ = bounds_->left_ + width;	setBounds( bounds_ );}void Control::setTop( const double& top ) /**throw( InvalidPeer ); -JEC - FIXME later*/{	double dy = bounds_->getHeight();	bounds_->top_ = top;	bounds_->bottom_ = top + dy;	setBounds( bounds_ );}void Control::setBottom( const double& bottom ) /**throw( InvalidPeer ); -JEC - FIXME later*/{	bounds_->bottom_ = bottom;	setBounds( bounds_ );}void Control::setHeight( const double& height ) /**throw( InvalidPeer ); -JEC - FIXME later*/{	if ( NULL != peer_ ){		bounds_->bottom_ = bounds_->top_ + height;		setBounds( bounds_ );	};}void Control::setVisible( const bool& visible ) /**throw( InvalidPeer ); -JEC - FIXME later*/{	bool oldVisible = peer_->getVisible();		if ( visible ) {		controlState_  |= Control::csVisible;	}	else {		controlState_  &= ~Control::csVisible;	}	if ( oldVisible != visible ) {	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -