window.cpp

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

CPP
536
字号
//Window.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/WindowPeer.h"#include "vcf/ApplicationKit/MenuManager.h"using namespace VCF;Window::Window(){	Application* app = Application::getRunningInstance();	Control* owner = NULL;	if ( NULL != app ) {		owner = app->getMainWindow();	}	windowPeer_ = UIToolkit::createWindowPeer( this, owner );	peer_ = dynamic_cast<ControlPeer*>(windowPeer_);	if ( NULL == peer_ ){		throw InvalidPeer( MAKE_ERROR_MSG(NO_PEER), __LINE__ );	}	peer_->create( this );	peer_->setControl( this );	menuBar_ = NULL;	setHeight( getPreferredHeight() );	setWidth( getPreferredWidth() );	//add a close handler to get notified of the closing window	FrameClose.addHandler( new WindowEventHandler<Window>( this, &Window::onClose, "onClose" ) );	EventHandler* ev = new GenericEventHandler<Frame> ( this, &Frame::handleEvent, "Frame::handleEvent" );	ComponentAdded += ev;	MenuManager::registerWindow( this );}Window::Window( Control* control ){	windowPeer_ = UIToolkit::createWindowPeer( this, control );	peer_ = dynamic_cast<ControlPeer*>(windowPeer_);	if ( NULL == peer_ ){		throw InvalidPeer( MAKE_ERROR_MSG(NO_PEER), __LINE__ );	}	peer_->create( this );	peer_->setControl( this );	menuBar_ = NULL;	setHeight( getPreferredHeight() );	setWidth( getPreferredWidth() );	//add a close handler to get notified of the closing window	FrameClose.addHandler( new WindowEventHandler<Window>( this, &Window::onClose, "onClose" ) );	EventHandler* ev = new GenericEventHandler<Window> ( this, &Window::handleEvent, "Window::handleEvent" );	ComponentAdded += ev;}Window::~Window(){	StringUtils::traceWithArgs( Format("In Window::~Window for instance %p\n") % this );}void Window::destroy(){	Frame::destroy();}void Window::paint(GraphicsContext * context){	Frame::paint( context );}void Window::setCaption( const String& caption ){	Frame::setCaption( caption );	String text = caption;		if ( getUseLocaleStrings() ) {		text = System::getCurrentThreadLocale()->translate( text );	}	peer_->setText( text );}Rect Window::getClientBounds(const bool& includeBorder){	if ( NULL == windowPeer_ ){		throw InvalidPeer(MAKE_ERROR_MSG(NO_PEER), __LINE__);	}	return windowPeer_->getClientBounds();}void  Window::setClientBounds( Rect* bounds ){	if ( NULL == windowPeer_ ){		throw InvalidPeer(MAKE_ERROR_MSG(NO_PEER), __LINE__);	}	windowPeer_->setClientBounds( bounds );}void Window::resizeChildren( Control* control ){	/*	Rect* bounds = getClientBounds();	Rect rect( 0.0, 0.0, bounds->getWidth(), bounds->getHeight() );	resizeChildrenUsingBounds( &rect );	*/	Frame::resizeChildren(control);}void Window::beforeDestroy( ComponentEvent* event ){	//remove me from my parent control if neccessary	Control* parent = getParent();	if ( NULL != parent ) {		Container* parentContainer = parent->getContainer();		if ( NULL != parentContainer ) {			//parentContainer->remove( this );		}	}	Frame::beforeDestroy( event );}MenuBar* Window::getMenuBar(){	return menuBar_;}void Window::setMenuBar( MenuBar* menuBar ){	menuBar_ = menuBar;	if ( NULL != menuBar_ ){		menuBar_->setFrame( this );		MenuManager::registerMenuBar( menuBar_ );	}}void Window::close(){	if ( this->allowClose() ) {		WindowEvent event( this, WINDOW_EVENT_CLOSE );		FrameClose.fireEvent( &event );		if ( NULL == windowPeer_ ){			throw InvalidPeer(MAKE_ERROR_MSG(NO_PEER), __LINE__);		}		windowPeer_->close();	}}void Window::onClose( WindowEvent* e ){	EventHandler* ev = new GenericEventHandler<Window>( this, &Window::postClose );	UIToolkit::postEvent( ev, new Event( this ) );}void Window::postClose( Event* event ){	//StringUtils::traceWithArgs( "Preparing to destroy window %p after a Window::close() call\n", this );	Application* app = Application::getRunningInstance();	if ( NULL != app ) {		if ( app->getMainWindow() == this ) {			return; //we're outta here - the main window will					//get cleaned up automagically		}	}	//check to nake sure we are not parented - if we are then we don't need to do	//delete our selves	if ( NULL != getParent() ) {		return;	}	//StringUtils::traceWithArgs( "Destroying window %p\n", this );	free();}void Window::setFrameStyle( const FrameStyleType& frameStyle ){	if ( NULL == windowPeer_ ){		throw InvalidPeer(MAKE_ERROR_MSG(NO_PEER), __LINE__);	}	frameStyle_ = frameStyle;	if ( !(Component::csDesigning & getComponentState()) ){		windowPeer_->setFrameStyle( frameStyle_ );	}}void Window::setFrameTopmost( const bool& isTopmost ){	Frame::setFrameTopmost( isTopmost );	if ( !(Component::csDesigning & getComponentState()) ){		if ( NULL == windowPeer_ ){			throw InvalidPeer(MAKE_ERROR_MSG(NO_PEER), __LINE__);		}		windowPeer_->setFrameTopmost( isTopmost );	}}double Window::getPreferredWidth(){	return 500.0;}double Window::getPreferredHeight(){	return 500.0;}bool Window::isMaximized(){	return windowPeer_->isMaximized();}void Window::setMaximized( const bool maximized ){	windowPeer_->setMaximized( maximized );}bool Window::isMinimized(){	return windowPeer_->isMinimized();}void Window::setMinimized( const bool& minimized ){	windowPeer_->setMinimized( minimized );}

⌨️ 快捷键说明

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