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

📄 control.cpp

📁 这是VCF框架的代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				if ( !isLoading() ) {			peer_->setVisible( visible );		}		Control* parent = getParent();		if ( NULL != parent ) {			Container* container = parent->getContainer();			if ( NULL != container ) {				if ( visible ) { //(oldVisible == false) && (true == visible) ) {					container->resizeChildren(NULL);//this);				}				else {					container->resizeChildren(NULL);				}			}		}	}}void Control::handleEventAndForwardToChildren( Event* event ){	handleEvent( event );	Container* container = getContainer();	if ( NULL != container && (!event->isConsumed())) {		Enumerator<Control*>* children = container->getChildren();		while ( children->hasMoreElements() )  {			Control* child = children->nextElement();			child->handleEventAndForwardToChildren( event );			if ( event->isConsumed() ) {				break;			}		}	}}void Control::handleEvent( Event* event ){	Component::handleEvent( event );	if ( NULL != event ){		unsigned long eventType = event->getType();		switch ( eventType ){			case Action::UpdateEvent : {				ActionEvent* actionEvent = (ActionEvent*)event;				setEnabled( actionEvent->isEnabled() );			}			break;			case CONTROL_SIZED:{				ControlEvent* controlEvent = (ControlEvent*)event;				//bounds_->right_ = bounds_->left_ + controlEvent->getNewSize().width_;				//bounds_->bottom_ = bounds_->top_ + controlEvent->getNewSize().height_;				ControlSized.fireEvent( (ControlEvent*)event );				if (!event->isConsumed() && !isDesigning()) {					sizeChange( controlEvent );				}				if ( isUsingRenderBuffer() ) {					Rect bounds = getClientBounds(false);					context_->setDrawingArea( bounds );										}			}			break;			case CONTROL_POSITIONED:{				ControlEvent* controlEvent = (ControlEvent*)event;				//double w = bounds_->getWidth();				//double h = bounds_->getHeight();				//bounds_->left_ = controlEvent->getNewPosition().x_;				//bounds_->top_ = controlEvent->getNewPosition().y_;				//bounds_->right_ = bounds_->left_ + w;				//bounds_->bottom_ = bounds_->top_ + h;				ControlPositioned.fireEvent( controlEvent );				if (!event->isConsumed() && !isDesigning()) {					positionChange( controlEvent );				}			}			break;			case CONTROL_PARENT_CHANGED:{				ControlParentChanged.fireEvent( (ControlEvent*)event );				if (!event->isConsumed() && !isDesigning()) {					parentChange( (ControlEvent*)event );				}			}			break;			case MOUSE_ENTERED:{				MouseEvent* mouseEvent = (MouseEvent*)event;				MouseEnter.fireEvent( mouseEvent );				if (!event->isConsumed() && !isDesigning()) {					mouseEnter( mouseEvent );				}			}			break;			case MOUSE_DOWN:{				MouseEvent* mouseEvent = (MouseEvent*)event;				clickPt_ = *mouseEvent->getPoint();								MouseDown.fireEvent( mouseEvent );				//turn off normal mouse behaviour in design mode				if ( !event->isConsumed() && !isDesigning() ) {					mouseDown( mouseEvent );				}			}			break;			case MOUSE_MOVE:{				MouseEvent* mouseEvent = (MouseEvent*)event;				if (mouseEvent->hasLeftButton() || mouseEvent->hasRightButton() || mouseEvent->hasMiddleButton() ) {					if ( (true == getAutoStartDragDrop()) ) { //&& (false == dragDropStarted_) ) {						if ( true == canBeginDragDrop( mouseEvent->getPoint() ) ) {							//dragDropStarted_ = true;														if ( beginDragDrop ( mouseEvent ) ) {								return;							}						}					}				}								peer_->setCursor( cursor_ );				MouseMove.fireEvent( mouseEvent );				if (!event->isConsumed() && !isDesigning()) {					mouseMove( mouseEvent );				}			}			break;			case MOUSE_UP:{				MouseEvent*  mouseEvent = (MouseEvent*)event;				Point tmpPt = *mouseEvent->getPoint();				Point origPt = *mouseEvent->getPoint();				bool rightBtn = mouseEvent->hasRightButton();				MouseUp.fireEvent( mouseEvent );				if (!mouseEvent->isConsumed() && !isDesigning()) {					mouseUp( mouseEvent );				}				if ( (true == rightBtn) && !isDesigning() ){					//(NULL != popupMenu_) && 					ControlPopupMenuMenuEvent e(this,Control::BEFORE_POPUP_MENU);					e.popupMenu = popupMenu_;					BeforePopupMenu.fireEvent( &e );					if ( !e.cancelPopup && (NULL != e.popupMenu) ) {						Point tmpPt = *mouseEvent->getPoint();						if ( NULL != scrollable_ ) {							tmpPt.x_ -= scrollable_->getHorizontalPosition();							tmpPt.y_ -= scrollable_->getVerticalPosition();						}						e.popupMenu->popup( &tmpPt );					}				}				if ( clickPt_.closeTo( tmpPt.x_, tmpPt.y_, 2 ) ){										MouseEvent clickEvent( this,											MOUSE_CLICK,											mouseEvent->getButtonMask(),											mouseEvent->getKeyMask(),											&origPt );					handleEvent( &clickEvent );				}			}			break;			case MOUSE_LEAVE:{				MouseEvent*  mouseEvent = (MouseEvent*)event;				MouseLeave.fireEvent( mouseEvent );				if (!mouseEvent->isConsumed() && !isDesigning()) {					mouseLeave( mouseEvent );				}			}			break;			case MOUSE_CLICK:{								MouseEvent*  mouseEvent = (MouseEvent*)event;				MouseClicked.fireEvent( mouseEvent );				if (!mouseEvent->isConsumed() && !isDesigning() ) {					mouseClick( mouseEvent );				}			}			break;			case MOUSE_DBLCLICK:{				MouseEvent*  mouseEvent = (MouseEvent*)event;				MouseDoubleClicked.fireEvent( mouseEvent );				if (!mouseEvent->isConsumed() && !isDesigning() ) {					mouseDblClick( mouseEvent );				}			}			break;			case KEYBOARD_DOWN:{				KeyboardEvent* kbEvent = (KeyboardEvent*)event;								if ( !isDesigning() || (NULL != getContainer()) ) {					keyDown( kbEvent );									}				KeyDown.fireEvent( kbEvent );			}			break;			case KEYBOARD_PRESSED:{				KeyboardEvent* kbEvent = (KeyboardEvent*)event;				if ( !isDesigning() || (NULL != getContainer()) ) {					keyPressed( kbEvent );				}								KeyPressed.fireEvent( kbEvent );			}			break;			case KEYBOARD_UP:{				KeyboardEvent* kbEvent = (KeyboardEvent*)event;				if ( !isDesigning() || (NULL != getContainer()) ) {					keyUp ( kbEvent );				}				KeyUp.fireEvent( kbEvent );			}			break;			case FOCUS_LOST:{				FocusEvent* focusEvent = (FocusEvent*)event;				//StringUtils::traceWithArgs( "Control::FOCUS_LOST, this[%s]@ %p\n",				//					getClassName().c_str(), this );				FocusLost.fireEvent( focusEvent );				if (!event->isConsumed() && !isDesigning()) {					lostFocus( focusEvent );				}			}			break;			case FOCUS_GAINED:{				FocusEvent* focusEvent = (FocusEvent*)event;				//StringUtils::traceWithArgs( "Control::FOCUS_GAINED, this[%s]@ %p\n",				//					getClassName().c_str(), this );				FocusGained.fireEvent( focusEvent );				if (!event->isConsumed() && !isDesigning()) {					gotFocus( focusEvent );				}			}			break;		}		//if ( !mouseEvent->isConsumed() )			//mouseEvent->setConsumed(true);	}}bool Control::canBeginDragDrop( Point* point ){	bool result = false;	Size dragDropDelta = UIToolkit::getDragDropDelta();	/**	clickPt_ gets set on a mousedown	so make a rect around it	r1 will be the inner  rect	r2 will be the outer rect	if the drag is outside the bounds of r1 and within r2	then we can do a drag, otherwise forget it	*/	Rect r1( clickPt_.x_ - dragDropDelta.width_ /2.0,			clickPt_.y_ - dragDropDelta.height_ /2.0,			clickPt_.x_ + dragDropDelta.width_ /2.0,			clickPt_.y_ + dragDropDelta.height_ /2.0 );	Rect r2 = r1;	r2.inflate( dragDropDelta.width_, dragDropDelta.height_ );	//we are only ready to to begin a drag drop operation	//if the point is NOT, I repeat, NOT, within the bounds of the	//drag-drop rect. This prevents us from starting too early.	//changing the dragDropDelta value allows us to control the 	//sensitivity of how we reacto to drag-drop starts	result = (!r1.containsPt( point )) && (r2.containsPt( point ));		return result;}void Control::setAutoStartDragDrop(const bool& canAutoStartDragDrop){	if ( canAutoStartDragDrop ) {		controlState_  |= Control::csAutoStartDragDrop;	}	else {		controlState_  &= ~Control::csAutoStartDragDrop;	}}bool Control::getAutoStartDragDrop(){	return (controlState_ & Control::csAutoStartDragDrop) ? true : false;}bool Control::beginDragDrop( MouseEvent* event ){	return false;}ControlPeer* Control::getPeer(){	return peer_;}void Control::setParent( Control* parent ) /**throw( InvalidPeer ); -JEC - FIXME later*/{	if ( parent != parent_ ) {		ControlEvent event( this, parent );		ControlParentChanged.fireEvent( &event );	}	parent_ = parent;	peer_->setParent( parent );	if ( NULL != parent_ ) {		if ( NULL == getOwner() ) {			parent->addComponent( this );		}		if ( parent_->isLightWeight() && !isLightWeight() ) {			Rect tmp = peer_->getBounds();			Rect tmp2 = tmp;			tmp.offset( -tmp.left_, -tmp.top_ );			translateToScreenCoords( &tmp );			parent->translateFromScreenCoords( &tmp );			tmp2.offset( tmp2.left_ - tmp.left_, tmp2.top_ - tmp.top_ );			*bounds_ = tmp2;			peer_->setBounds( &tmp2 );		}	}	updateAnchorDeltas();}Control* Control::getParent() /**throw( InvalidPeer ); -JEC - FIXME later*/{	return parent_;}void Control::removeFromParent( const bool& freeInstance ){	Control* parent = getParent();	if ( NULL != parent ) {		Container* container = parent->getContainer();		VCF_ASSERT( NULL != container );		container->remove( this );			}	removeFromOwner( freeInstance );}bool Control::isFocused(){	bool result = (this == currentFocusedControl);	return result;//peer_->isFocused();}Control* Control::setFocused(){	Control* result = NULL;	if ( isNormal() || isCreated() || isDesigning() ) {	//JC added this so that a control recv's focus														//only under these conditions			if ( NULL != currentFocusedControl ) {				if ( this != currentFocusedControl ) {					//currentFocusedControl->setFocus( false ); //is this neccessary ?					// do this to get the non focused control to repaint it's state					currentFocusedControl->repaint();				}			}		result = currentFocusedControl;		currentFocusedControl = this;		peer_->setFocused();	}	repaint();	return result;}bool Control::isEnabled(){	return (controlState_ & Control::csEnabled) ? true : false;//peer_->isEnabled();}bool Control::areParentsEnabled(){	if ( !isEnabled() ) {		return false;	}	bool result = true;	Control* parent = getParent();	while ( result && (NULL != parent) ) {		result = parent->isEnabled();		parent = parent->getParent();	}	return result;}void Control::setEnabled( const bool& enabled ){	if ( enabled ) {		controlState_  |= Control::csEnabled;	}

⌨️ 快捷键说明

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