toolbar.cpp

来自「这是VCF框架的代码」· C++ 代码 · 共 694 行 · 第 1/2 页

CPP
694
字号
//Toolbar.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/Toolbar.h"#include "vcf/ApplicationKit/ToolbarPeer.h"#include "vcf/ApplicationKit/Action.h"#include "vcf/ApplicationKit/ActionEvent.h"#include "vcf/GraphicsKit/DrawUIState.h"using namespace VCF;//******************************************************************************//ToolbarItem//******************************************************************************ToolbarItem::ToolbarItem():	data_(NULL),	imageIndex_(0),	imageStateIndex_(0),	itemControl_(NULL){	tag_ = -1;	itemState_ = tisEnabled;}void ToolbarItem::click(){	ButtonEvent event( this, ToolbarItem::tbItemClicked );	Action* action = getAction();	if ( NULL != action ) {		action->perform( &event );	}	else {		ItemClicked.fireEvent( &event );	}}bool ToolbarItem::updateAction(){	if ( !Component::updateAction() ) {		Event event( this, ToolbarItem::tbItemUpdate );		ItemUpdate.fireEvent( &event );		return true;	}	return false;}void ToolbarItem::handleEvent( Event* event ){	Component::handleEvent( event );	switch ( event->getType() ){		case Action::UpdateEvent : {			ActionEvent* actionEvent = (ActionEvent*)event;			setEnabled( actionEvent->isEnabled() );			Toolbar* toolbar = (Toolbar*)getControl();			if ( NULL != toolbar ) {				if ( toolbar->getShowButtonCaptions() ) {					setCaption( actionEvent->getText() );				}				else {					setTooltip( actionEvent->getText() );				}			}			if ( this->isChecked() && (actionEvent->getState() & tisPressed) ) {				setPressed( true );			}			else if ( isChecked() ) {				setPressed( false );			}		}		break;						}}bool ToolbarItem::containsPoint( Point * pt ){	return bounds_.containsPt(pt);}void ToolbarItem::setItemControl( Control* control ){	itemControl_ = control;	if ( NULL != model_ ) {		((ToolbarModel*)model_)->itemChanged( ToolbarItem::tbItemControlAdded, this );	}}void ToolbarItem::setAsSeparator(){	setState( tisSeparator );}void ToolbarItem::setPressed( bool val ){	if ( ( (itemState_ & ToolbarItem::tisPressed) != 0 ) == val ) {		return;	}	long state = itemState_;	if ( val ) {		state |= tisPressed;	}	else {		state &= ~tisPressed;	}	setState( state );}bool ToolbarItem::isEnabled(){	return (itemState_ & ToolbarItem::tisEnabled) ? true : false;}void ToolbarItem::setEnabled( const bool& val ){	if ( isEnabled() == val ) {		return;	}	long state = itemState_;	if ( val ) {		state |= ToolbarItem::tisEnabled;	}	else {		state &= ~ToolbarItem::tisEnabled;	}	setState( state );}void ToolbarItem::setState( const long& state ){	if ( itemState_ == state ) {		return ;	}	itemState_ = state;	if ( NULL != model_ ) {		((ToolbarModel*)model_)->itemChanged( ToolbarItem::tbStateChanged, this );	}}void ToolbarItem::setStateImageIndex( const long& index ){	imageStateIndex_ = index;	if ( NULL != model_ ) {		((ToolbarModel*)model_)->itemChanged( ToolbarItem::tbStateImageIndexChanged, this );	}}ulong32 ToolbarItem::getIndex(){	return ((ToolbarModel*)model_)->getItemIndex(this);}void ToolbarItem::setImageIndex( const long& imageIndex ){	imageIndex_ = imageIndex;	if ( NULL != model_ ) {		((ToolbarModel*)model_)->itemChanged( ToolbarItem::tbImageIndexChanged, this );	}}void ToolbarItem::setIndex( const unsigned long& index ){	//no-op}bool ToolbarItem::isSelected(){	return (itemState_ & tisSelected) ? true : false;}void ToolbarItem::setSelected( const bool& selected ){	if ( isSelected() == selected ) {		return;	}	if ( selected ) {		itemState_ |= tisSelected;	}	else {		itemState_ &= ~tisSelected;	}	if ( NULL != model_ ) {		((ToolbarModel*)model_)->itemChanged( ToolbarItem::tbSelected, this );	}}void ToolbarItem::internal_setBounds( const Rect& bounds ) //Parameter made const for ANSI compliance - ACH{	bounds_ = bounds;	if ( NULL != itemControl_ ) {		Rect controlBounds = itemControl_->getBounds();		//if ( !(controlBounds == bounds_) ) {			itemControl_->setBounds( &bounds_ );		//}	}}void ToolbarItem::setBounds( Rect* bounds ){	internal_setBounds( *bounds );	if ( NULL != model_ ) {		((ToolbarModel*)model_)->itemChanged( ToolbarItem::tbDimensionsChanged, this );	}}void ToolbarItem::setWidth( const double& val ){	bounds_.right_ = bounds_.left_ + val;	if ( NULL != model_ ) {		((ToolbarModel*)model_)->itemChanged( ToolbarItem::tbDimensionsChanged, this );	}}void ToolbarItem::setCaption( const String& val ){	if ( val == caption_ ) {		return;	}	caption_ = val;	if ( NULL != model_ ) {		((ToolbarModel*)model_)->itemChanged( ToolbarItem::tbCaptionChanged, this );	}}void ToolbarItem::setTooltip( const String& val ){	if ( val == tooltip_ ) {		return;	}	tooltip_ = val;	if ( NULL != model_ ) {		((ToolbarModel*)model_)->itemChanged( ToolbarItem::tbTooltipChanged, this );	}}void ToolbarItem::setGrouped( const bool& val ){	if ( val == isGrouped() ) {		return;	}	if ( val ) {		itemState_ |= tisGrouped;	}	else {		itemState_ &= ~tisGrouped;	}	if ( NULL != model_ ) {		((ToolbarModel*)model_)->itemChanged( ToolbarItem::tbGroupChanged, this );	}}bool ToolbarItem::isGrouped(){	return (itemState_ & tisGrouped) ? true : false;}void ToolbarItem::setChecked( const bool& val ){	if ( val == isChecked() ) {		return;	}	if ( val ) {		itemState_ |= tisChecked;	}	else {		itemState_ &= ~tisChecked;	}	if ( NULL != model_ ) {		((ToolbarModel*)model_)->itemChanged( ToolbarItem::tbCheckChanged, this );	}}bool ToolbarItem::isChecked(){	return (itemState_ & tisChecked) ? true : false;}//******************************************************************************//ToolbarModel//******************************************************************************ToolbarModel::ToolbarModel(){	itemsContainer_.initContainer( toolbarItems_ );}ToolbarModel::~ToolbarModel(){	std::vector<ToolbarItem*>::iterator it = toolbarItems_.begin();	while ( it != toolbarItems_.end() ) {		ToolbarItem* item = *it;		item->release();		it ++;	}	toolbarItems_.clear();}void ToolbarModel::addItem( ToolbarItem* item ){	toolbarItems_.push_back( item );	item->setModel( this );	itemChanged( ToolbarItem::tbAdded, item );}void ToolbarModel::insertItem( ToolbarItem* item, const ulong32& index ){	toolbarItems_.insert( toolbarItems_.begin() + index, item );	item->setModel( this );	itemChanged( ToolbarItem::tbAdded, item );}void ToolbarModel::removeItem( ToolbarItem* item ){	std::vector<ToolbarItem*>::iterator found = std::find( toolbarItems_.begin(), toolbarItems_.end(), item );

⌨️ 快捷键说明

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