osxdialog.cpp

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

CPP
615
字号
//OSXDialog.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/ApplicationKitPrivate.h"#include "vcf/ApplicationKit/OSXDialog.h"#include "vcf/ApplicationKit/OSXControl.h"using namespace VCF;OSXDialog::OSXDialog()	:	owner_(NULL),	dialogComponent_(NULL),	dialogRef_(NULL),	isWindowSheet_(false){}OSXDialog::OSXDialog( Control* owner, Dialog* component ):	owner_(owner),	dialogComponent_(component),	dialogRef_(NULL),	isWindowSheet_(false){	}OSXDialog::~OSXDialog(){}WindowAttributes OSXDialog::getCreationWinAttrs(){	return kWindowCompositingAttribute |              kWindowStandardHandlerAttribute | kWindowLiveResizeAttribute;}WindowClass OSXDialog::getCreationWinClass(){	/*	Dialog* dialog = (Dialog*)control_;	if ( NULL != dialog ) {		if ( dialog->isSheetModal() ) {			return kSheetAlertWindowClass;		}		else if ( dialog->isModal() ) {			return kMovableModalWindowClass;		}	}	*/	return kDocumentWindowClass;}void OSXDialog::createAsSheetWindow(){	sheetParent_ = NULL;	WindowAttributes attrs = kWindowCompositingAttribute | kWindowStandardHandlerAttribute;		::Rect bounds = {0,0,0,0};		OSStatus err = CreateNewWindow( kSheetAlertWindowClass, attrs, &bounds, &windowRef_ );	if ( noErr != err ) {		throw RuntimeException( MAKE_ERROR_MSG_2("CreateNewWindow() failed!") );	}	else {		isWindowSheet_ = true;			OSXDialog* thisPtr = this;		err = SetWindowProperty( windowRef_, 								 VCF_PROPERTY_CREATOR, 								 VCF_PROPERTY_WINDOW_VAL, 								 sizeof(OSXDialog*), 								 &thisPtr );				if ( noErr != err ) {			throw RuntimeException( MAKE_ERROR_MSG_2("SetWindowProperty() failed!") );		}				static EventTypeSpec eventsToHandle[] ={			// { kEventClassWindow, kEventWindowGetIdealSize },			//{ kEventClassCommand, kEventCommandProcess },			//{ kEventClassCommand, kEventCommandUpdateStatus },		{ kEventClassWindow, kEventWindowClose },		{ kEventClassWindow, kEventWindowActivated },		{ kEventClassWindow, kEventWindowDeactivated },		{ kEventClassWindow, kEventWindowFocusAcquired },		{ kEventClassWindow, kEventWindowFocusRelinquish },					{ kEventClassWindow, kEventWindowDrawContent },		{ kEventClassMouse, kEventMouseDown },		{ kEventClassMouse, kEventMouseUp },		{ kEventClassMouse, kEventMouseMoved },		{ kEventClassMouse, kEventMouseDragged },		{ kEventClassMouse, kEventMouseEntered },		{ kEventClassMouse, kEventMouseExited },		{ kEventClassMouse, kEventMouseWheelMoved },		{ kEventClassKeyboard, kEventRawKeyDown },		{ kEventClassKeyboard, kEventRawKeyUp },		{ kEventClassWindow, kEventWindowBoundsChanged } };						InstallWindowEventHandler( windowRef_,								   OSXWindow::getEventHandlerUPP(),								   sizeof(eventsToHandle)/sizeof(eventsToHandle[0]),								   eventsToHandle,								   this,								   &handlerRef_ );				static EventTypeSpec contentViewEvents[] ={ { kEventClassControl, kEventControlDraw } };				ControlRef root = getRootControl();		InstallEventHandler( GetControlEventTarget( root ), 							OSXWindow::wndContentViewHandler,							sizeof(contentViewEvents) / sizeof(EventTypeSpec), 							contentViewEvents, 							this, 							&contentViewHandlerRef_ );											Frame* ownerFrame = owner_->getParentFrame();		sheetParent_ = (WindowRef) ownerFrame->getPeer()->getHandleID();	}}void OSXDialog::createAsWindow(){	sheetParent_ = NULL;	WindowAttributes attrs=getCreationWinAttrs();// = kWindowCompositingAttribute | kWindowStandardHandlerAttribute;        ::Rect bounds = {0,0,0,0};    OSStatus err = CreateNewWindow( getCreationWinClass(), attrs, &bounds, &windowRef_ );    if ( noErr != err ) {        throw RuntimeException( MAKE_ERROR_MSG_2("CreateNewWindow() failed!") );    }    else {		OSXWindow* thisPtr = this;        err = SetWindowProperty( windowRef_, 								VCF_PROPERTY_CREATOR, 								VCF_PROPERTY_WINDOW_VAL, 								sizeof(OSXWindow*), 								&thisPtr );		isWindowSheet_ = false;				if ( noErr != err ) {            throw RuntimeException( MAKE_ERROR_MSG_2("SetWindowProperty() failed!") );        }				SetThemeWindowBackground( windowRef_, kThemeBrushSheetBackgroundTransparent, true );		        static EventTypeSpec eventsToHandle[] ={                            // { kEventClassWindow, kEventWindowGetIdealSize },                            //{ kEventClassCommand, kEventCommandProcess },                            //{ kEventClassCommand, kEventCommandUpdateStatus },                            { kEventClassWindow, kEventWindowClose },                            { kEventClassWindow, kEventWindowActivated },                            { kEventClassWindow, kEventWindowDeactivated },                            { kEventClassWindow, kEventWindowFocusAcquired },                            { kEventClassWindow, kEventWindowFocusRelinquish },                            { kEventClassWindow, kEventWindowDrawContent },                            { kEventClassMouse, kEventMouseDown },                            { kEventClassMouse, kEventMouseUp },                            { kEventClassMouse, kEventMouseMoved },                            { kEventClassMouse, kEventMouseDragged },                            { kEventClassMouse, kEventMouseEntered },                            { kEventClassMouse, kEventMouseExited },                            { kEventClassMouse, kEventMouseWheelMoved },                            { kEventClassKeyboard, kEventRawKeyDown },                            { kEventClassKeyboard, kEventRawKeyUp },                            { kEventClassWindow, kEventWindowBoundsChanged } };        InstallWindowEventHandler( windowRef_,                                    OSXWindow::getEventHandlerUPP(),                                    sizeof(eventsToHandle)/sizeof(eventsToHandle[0]),                                    eventsToHandle,                                    this,                                    &handlerRef_ );								static EventTypeSpec contentViewEvents[] ={ { kEventClassControl, kEventControlDraw } };				ControlRef root = getRootControl();		InstallEventHandler( GetControlEventTarget( root ), 							OSXWindow::wndContentViewHandler,							sizeof(contentViewEvents) / sizeof(EventTypeSpec), 							contentViewEvents, 							this, 							&contentViewHandlerRef_ );	}}void OSXDialog::create( Control* owningControl ){	if ( NULL == owner_ ) {		OSXWindow::create( owningControl );	}	else {		control_ = owningControl;				createAsSheetWindow();							UIToolkit::postEvent( new GenericEventHandler<Control>( owningControl, &Control::handleEvent ),								  new VCF::ComponentEvent( owningControl, Component::COMPONENT_CREATED ),	true );								}}void OSXDialog::setBounds( Rect* rect ){	realSheetBounds_ = *rect;		OSXWindow::setBounds( rect );}VCF::Rect OSXDialog::getBounds(){	VCF::Rect result;		if ( isWindowSheet_ && !getVisible() ) {		result = realSheetBounds_;	}	else {		result = OSXWindow::getBounds();	}		return result;}void OSXDialog::setVisible( const bool& visible ){	//we are being displayed - chewck if we need to 	//"turn into" a sheet from a dialog, or vice-versa	Dialog* dialog = (Dialog*)control_;	if ( dialog->isSheetModal() ) {		//check if we are alread a sheet		if ( !isWindowSheet_ ) {			//oops! We are not a sheet! Store off			//our current window ref, create a new sheet			//window, and transfer the controls from our old window ref			//to our new sheet!			VCF::Rect oldBounds = control_->getBounds();			String oldCaption = getText();			WindowRef oldWnd = windowRef_;			//remove old handler!!!			RemoveEventHandler( handlerRef_ );						RemoveEventHandler( contentViewHandlerRef_ );						contentViewHandlerRef_ = NULL;			handlerRef_ = NULL;			windowRef_ = NULL;						//creates a new sheet			createAsSheetWindow();						//copies over the controls from the wnd to the sheet			copyControlsFromWndRef( oldWnd );						//kill the old window			DisposeWindow( oldWnd );						//reset the bounds			control_->setBounds( &oldBounds );						setText( oldCaption );		}	}//	else if ( dialog->isModal() ) {	//no-op for now??//	}	else {		if ( isWindowSheet_ ) {			//oops we are a sheet! Transfer us back into a regular window!			VCF::Rect oldBounds = realSheetBounds_;			String oldCaption = getText();						WindowRef oldWnd = windowRef_;						//remove old handler!!!			RemoveEventHandler( handlerRef_ );						RemoveEventHandler( contentViewHandlerRef_ );						contentViewHandlerRef_ = NULL;			handlerRef_ = NULL;			windowRef_ = NULL;						createAsWindow();						//copies over the controls from the wnd to the sheet			copyControlsFromWndRef( oldWnd );						//kill the old window			DisposeWindow( oldWnd );						//reset the bounds

⌨️ 快捷键说明

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