osxcontext.cpp

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

CPP
2,398
字号
        if ( edgeSides & GraphicsContext::etRightSide ) {            OSXRect tmp = &modRect;			::Rect r = tmp;            r.left = r.right;            DrawThemeSeparator( &r, state.isActive() ? kThemeStateActive : kThemeStateInactive );        }        if ( edgeSides & GraphicsContext::etTopSide ) {            OSXRect tmp = &modRect;			::Rect r = tmp;            r.bottom = r.top;            DrawThemeSeparator( &r, state.isActive() ? kThemeStateActive : kThemeStateInactive );        }        if ( edgeSides & GraphicsContext::etBottomSide ) {            OSXRect tmp = &modRect;			::Rect r = tmp;            r.top = r.bottom;            DrawThemeSeparator( &r, state.isActive() ? kThemeStateActive : kThemeStateInactive );        }    }}void OSXContext::drawThemeSizeGripper( Rect* rect, DrawUIState& state ){	Rect tmp = *rect;	tmp.offset( origin_.x_, origin_.y_ );		::Rect bounds;    ::Point gripperOrigin;    gripperOrigin.h = (int)tmp.left_;    gripperOrigin.v = (int)tmp.top_;    GetThemeStandaloneGrowBoxBounds( gripperOrigin, 0, FALSE, &bounds );    gripperOrigin.h = (int)(tmp.right_ - (bounds.right-bounds.left));    gripperOrigin.v = (int)(tmp.bottom_ - (bounds.bottom-bounds.top));    DrawThemeStandaloneGrowBox( gripperOrigin, 0, FALSE,  state.isActive() ? kThemeStateActive : kThemeStateInactive );}void OSXContext::drawThemeBackground( Rect* rect, BackgroundState& state ){	Rect tmp = *rect;	tmp.offset( origin_.x_, origin_.y_ );	OSXRect r = &tmp;	OSStatus err = 0;		Color* color = GraphicsToolkit::getSystemColor( state.colorType_ );	float colorComponents[4] =			{color->getRed(),			color->getGreen(),			color->getBlue(), 1.0};		switch ( state.colorType_ ) {		case SYSCOLOR_SHADOW : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );												}		break;				case SYSCOLOR_FACE : {			err = SetThemeBackground( state.isActive() ? kThemeBrushButtonFaceActive : kThemeBrushButtonFaceInactive,									32, TRUE );			if ( err != noErr ) {				StringUtils::traceWithArgs( Format("SetThemeBackground() failed, err: %d\n") % err );			}			EraseRect( r );		}		break;				case SYSCOLOR_HIGHLIGHT : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}		break;				case SYSCOLOR_ACTIVE_CAPTION : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}		break;				case SYSCOLOR_ACTIVE_BORDER : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}		break;				case SYSCOLOR_DESKTOP : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}		break;				case SYSCOLOR_CAPTION_TEXT : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}		break;				case SYSCOLOR_SELECTION_TEXT : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}		break;				case SYSCOLOR_INACTIVE_BORDER : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}		break;				case SYSCOLOR_INACTIVE_CAPTION : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}   		break;				case SYSCOLOR_TOOLTIP : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}		break;				case SYSCOLOR_TOOLTIP_TEXT : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}		break;				case SYSCOLOR_MENU : {								err = SetThemeBackground( state.isHighlighted() ? kThemeBrushMenuBackgroundSelected : kThemeBrushMenuBackground,									32, TRUE );			if ( err != noErr ) {				StringUtils::traceWithArgs( Format("SetThemeBackground() failed, err: %d\n") % err );			}						EraseRect( r );		}		break;				case SYSCOLOR_MENU_TEXT : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}		break;				case SYSCOLOR_WINDOW : {			err = SetThemeBackground( state.isActive() ? kThemeBrushUtilityWindowBackgroundActive : kThemeBrushUtilityWindowBackgroundInactive,									32, TRUE );												if ( err != noErr ) {				StringUtils::traceWithArgs( Format("SetThemeBackground() failed, err: %d\n") % err );			}						EraseRect( r );		}		break;				case SYSCOLOR_WINDOW_TEXT : {			CGContextSetRGBFillColor( contextID_, colorComponents[0], colorComponents[1],										colorComponents[2], colorComponents[3] );			CGContextBeginPath( contextID_ );			CGContextAddRect( contextID_, r );			CGContextClosePath( contextID_ );			CGContextFillPath ( contextID_ );		}		break;				case SYSCOLOR_WINDOW_FRAME : {			SetThemeBackground( state.isActive() ? kThemeBrushDocumentWindowBackground : kThemeBrushDocumentWindowBackground,									32, TRUE );			EraseRect( r );					}		break;	}}void OSXContext_drawThemeMenuItemText ( const ::Rect * inBounds, SInt16 inDepth, 										Boolean inIsColorDevice, SInt32 inUserData ){	MenuState* state = (MenuState*)inUserData;	CFTextString cfStr;	cfStr = state->menuCaption_;	int menuState;	if ( state->isActive() ) {		menuState = kThemeStateActive;	}	else if ( state->isSelected() ) {		menuState = kThemeStatePressed;	}	else if ( !state->isEnabled() ) {		menuState = kThemeStateInactive;	}		::DrawThemeTextBox( cfStr, kThemeMenuItemFont, menuState, false, inBounds,			teFlushDefault, NULL );} void OSXContext::drawThemeMenuItem( Rect* rect, MenuState& state ){	Rect tmp = *rect;	tmp.offset( origin_.x_, origin_.y_ );	OSXRect r = &tmp;	::Point pt;	::Rect menuRect = r;	pt.h = menuRect.left;	pt.v = menuRect.top;			//LocalToGlobal( &pt );	//	menuRect.left = pt.h;//	menuRect.top = pt.v;			pt.h = menuRect.right;	pt.v = menuRect.bottom;	LocalToGlobal( &pt );	//	menuRect.right = pt.h;//	menuRect.bottom = pt.v;		::Rect menuItemRect = menuRect;		ThemeMenuState menuState = kThemeMenuActive;	if ( state.isSelected() ) {		menuState = kThemeMenuSelected;	}	else if ( !state.isEnabled() ) {		menuState = kThemeMenuDisabled;	}		MenuItemDrawingUPP menuDrawUPP = NewMenuItemDrawingUPP(OSXContext_drawThemeMenuItemText);	    		DrawThemeMenuItem( &menuRect, &menuItemRect, menuRect.top, menuRect.bottom, 						menuState, kThemeMenuItemPlain, menuDrawUPP, (UInt32)&state );							DisposeMenuItemDrawingUPP(menuDrawUPP);	}void OSXContext::drawThemeMenuItemText( Rect* rect, MenuState& state ){}void OSXContext::drawThemeText( Rect* rect, TextState& state ){	Rect tmp = *rect;	tmp.offset( origin_.x_, origin_.y_ );	OSXRect r = &tmp;			ThemeTextColor textColor = kThemeTextColorDialogActive;	int menuState = kThemeStateActive;		if ( state.isSelected() ) {		menuState = kThemeStatePressed;	}	else if ( (!state.isEnabled()) || (!state.isActive()) ) {		menuState = kThemeStateInactive;		textColor = kThemeTextColorDialogInactive;	}			ThemeFontID fontID = 0;	switch ( state.themeFontType_ ) {		case GraphicsContext::ttMenuItemFont : {			fontID = kThemeMenuItemFont;		}		break;				case GraphicsContext::ttSelectedMenuItemFont : {			fontID = kThemeMenuItemFont;		}		break;				case GraphicsContext::ttSystemFont : {			fontID = kThemeSystemFont;		}		break;				case GraphicsContext::ttSystemSmallFont : {			fontID = kThemeSmallSystemFont;		}		break;				case GraphicsContext::ttControlFont : {			fontID = kThemeApplicationFont;		}		break;				case GraphicsContext::ttMessageFont : {			fontID = kThemeAlertHeaderFont;		}		break;				case GraphicsContext::ttToolTipFont : {			fontID = kThemeLabelFont;		}   		break;			}		/*	teJustLeft  teJustCenter  teJustRight  teForceLeft		// new names for the Justification (word alignment) styles   teFlushDefault	//flush according to the line direction   teCenter			//center justify (word alignment)   teFlushRight		//flush right for all scripts   teFlushLeft  */  	CFTextString cfStr;	cfStr = state.text_;		::SetThemeTextColor( textColor, 32, true );		::DrawThemeTextBox( cfStr, fontID, menuState, state.wrapText_, r,						teFlushDefault, NULL );}			/***CVS Log info*$Log$*Revision 1.6  2006/04/07 02:35:41  ddiego*initial checkin of merge from 0.6.9 dev branch.**Revision 1.5.2.6  2006/03/17 03:08:12  ddiego*updated osx code to latest changes.**Revision 1.5.2.5  2006/02/26 23:44:10  ddiego*minor updates to sync osx version with latest cvs. added xcode proj for Themes example.**Revision 1.5.2.4  2006/02/22 01:26:22  ddiego*mac osx updates.**Revision 1.5.2.3  2006/01/09 02:22:31  ddiego*more osx code**Revision 1.5.2.2  2005/11/27 23:55:45  ddiego*more osx updates.**Revision 1.5.2.1  2005/11/10 02:02:39  ddiego*updated the osx build so that it*compiles again on xcode 1.5. this applies to the foundationkit and graphicskit.**Revision 1.5  2005/07/09 23:06:00  ddiego*added missing gtk files**Revision 1.4  2005/01/08 20:52:47  ddiego*fixed some glitches in osx impl.**Revision 1.3.2.3  2005/06/28 04:09:05  ddiego*adjusted for marcellos change.**Revision 1.3.2.2  2005/05/08 19:55:32  ddiego*osx updates, not yet functional.**Revision 1.3.2.1  2005/03/15 01:51:54  ddiego*added support for Format class to take the place of the*previously used var arg funtions in string utils and system. Also replaced*existing code in the framework that made use of the old style var arg*functions.**Revision 1.3  2004/12/01 04:31:43  ddiego*merged over devmain-0-6-6 code. Marcello did a kick ass job*of fixing a nasty bug (1074768VCF application slows down modal dialogs.)*that he found. Many, many thanks for this Marcello.**Revision 1.2.2.5  2004/11/15 05:41:28  ddiego*finished almost all the osx menu code except for custom drawing. This completes this releases osx effort.**Revision 1.2.2.4  2004/11/06 18:21:51  chriskr*small bugfixes and optimizations for line-drawing**Revision 1.2.2.3  2004/10/27 03:12:18  ddiego*integrated chrisk changes**Revision 1.2.2.2  2004/10/23 18:10:46  ddiego*mac osx updates, some more fixes for dialog code and for command button peer functionality**Revision 1.2.2.1  2004/10/10 15:24:00  ddiego*updated os x code in graphics stuff.**Revision 1.2  2004/08/07 02:49:17  ddiego*merged in the devmain-0-6-5 branch to stable**Revision 1.1.2.12  2004/08/01 23:40:17  ddiego*fixed a few osx bugs**Revision 1.1.2.11  2004/07/27 04:26:04  ddiego*updated devmain-0-6-5 branch with osx changes**Revision 1.1.2.10.2.7  2004/07/09 02:01:29  ddiego*more osx updates**Revision 1.1.2.10.2.6  2004/07/06 03:27:13  ddiego*more osx updates that add proper support*for lightweight controls, some fixes to text layout, and some window painting issues. Also a fix*so that controls and windows paint either their default theme background or their background*color.**Revision 1.1.2.10.2.5  2004/06/27 18:19:16  ddiego*more osx updates**Revision 1.1.2.10.2.4  2004/06/20 00:36:11  ddiego*finished the new theme API updates**Revision 1.1.2.10.2.3  2004/06/17 03:00:24  ddiego*further updates to OSX theme compliant drawing code**Revision 1.1.2.10.2.2  2004/06/16 05:18:56  ddiego*further updates to OSX theme compliant drawing code**Revision 1.1.2.10.2.1  2004/06/15 04:04:38  ddiego*revamped osx theme drawing API**Revision 1.1.2.10  2004/06/07 03:07:07  ddiego*more osx updates dealing with mouse handling**Revision 1.1.2.9  2004/06/06 07:05:34  marcelloptr*changed macros, text reformatting, copyright s

⌨️ 快捷键说明

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