Пример #1
0
//*****************************************************************************
//
// Function Name:  CHeadlineSheet::OnPaint
//
// Description:    WM_PAINT handler
//
// Returns:        VOID
//
// Exceptions:	   None
//
//*****************************************************************************
//
void CHeadlineSheet::OnPaint( )
	{
	PAINTSTRUCT ps;
	HDC hdc = ::BeginPaint( GetSafeHwnd( ), &ps );

	// Put it in a DcDrawingSurface
	RDcDrawingSurface drawingSurface;
	drawingSurface.Initialize( hdc );

	// Create a transform
	R2dTransform transform;

	// Scale to the device DPI
	RRealSize deviceDPI = drawingSurface.GetDPI( );
	transform.PreScale( (YFloatType)deviceDPI.m_dx / kSystemDPI, (YFloatType)deviceDPI.m_dy / kSystemDPI );

	// Get the preview rectangle
	RRealRect previewRect;
	GetPreviewRect( &previewRect );

	// Offset the transform by the top left corner of the preview rect
	transform.PreTranslate( previewRect.m_Left, previewRect.m_Top );

	// Render the preview headline
	m_pPreviewHeadline->Render( drawingSurface, transform, RRealRect( previewRect.WidthHeight( ) ), previewRect.WidthHeight( ) );

	drawingSurface.DetachDCs( );

	::EndPaint( GetSafeHwnd( ), &ps );
	}
Пример #2
0
// ****************************************************************************
//
//  Function Name:	RGroupSelectionAction::Do( )
//
//  Description:		Does the action
//
//  Returns:			TRUE if the action was sucessful
//
//  Exceptions:		None
//
// ****************************************************************************
//
BOOLEAN RGroupSelectionAction::Do( )
	{
	// Call the base method to setup the state properly
	RUndoableAction::Do( );

	// Bail if the component was'nt created properly
	if( !m_pGroupDocument )
		return FALSE;																			

	// Get the z position of the top most component to use  as the group components z-position
	RView* pParentView = m_pCurrentSelection->GetView( );
	YSelectionIterator iterator = m_OldSelection.Start( );
	YComponentZPosition groupZPosition = pParentView->GetComponentZPosition( *iterator );

	// Make a component collection
	RComponentCollection componentCollection ( m_OldSelection );

	// Unselect the current selection
	m_pCurrentSelection->UnselectAll( );

	// Add the group component
	m_pParentDocument->AddComponent( m_pGroupDocument );

	// Transfer the components to the group
	m_pGroupDocument->TransferComponents( m_pParentDocument,
													  componentCollection,
													  componentCollection.GetBoundingRect( ),
													  RRealRect( m_GroupBoundingRect.WidthHeight( ) ) );

	// Combine the component attributes of the collection with that of the group
	RComponentAttributes attributes = m_pGroupDocument->GetComponentAttributes( );
	componentCollection.CombineAttributes( attributes );
	m_pGroupDocument->SetComponentAttributes( attributes );

	// Set the z position of the group component
	pParentView->SetComponentZPosition( m_pGroupDocument->GetView( pParentView ), groupZPosition );

	//	Tell the view that its layout has changed
	m_pCurrentSelection->GetView()->XUpdateAllViews( kLayoutChanged, 0 );

	// Select the group component
	m_pCurrentSelection->Select( m_pGroupDocument, TRUE );

	return TRUE;
	}
Пример #3
0
//////////////////////////////////////////////////////////////////////////////
//
//	void ExportGraphicComponent( RComponentView* pComponentView, RMBCString *pInitialDir ) 
//
//	export a graphic to file from a component view
//
//////////////////////////////////////////////////////////////////////////////
void ExportGraphicComponent( RComponentView* pComponentView, RMBCString *pInitialDir /*=NULL*/) 
{
	RImageLibrary rLibrary ;
	CArray<int, int> arrFileFormats ;

	//
	// Build the export file filter list...
	//
	CString strFilter, str ;

	for (int i = 0; i < kNumFormats - 1; i++)
	{
		if (rLibrary.IsFormatSupported( (EImageFormat) kImageExportFilters[i][0] ))
		{
			str.LoadString( kImageExportFilters[i][1] ) ;
			strFilter += str ;

			arrFileFormats.Add( kImageExportFilters[i][0] ) ;
		}
	}

	TpsAssert( kImageExportFilters[i][0] == kImageFormatXRX, "Invalid export format!" ) ;
	str.LoadString( kImageExportFilters[i][1] ) ;  
	strFilter += str ;
	strFilter += "|" ;

	arrFileFormats.Add( kImageExportFilters[i][0] ) ;

	//
	// Create and execute the dialog...
	//
	RExportGraphicDlg dlg( pComponentView, strFilter ) ;

	// Load in the dialog title string
	CString strTitle ;
	strTitle.LoadString( STRING_EXPORT_IMAGE_DIALOG_TITLE ) ;
	dlg.m_ofn.lpstrTitle = (LPCTSTR) strTitle ;
	if( pInitialDir )
	{
		dlg.m_ofn.lpstrInitialDir = (LPCTSTR)*pInitialDir;
	}

	if (IDOK == dlg.DoModal())
	{
		RMBCString   strPathName = dlg.GetPathName() ;
		RIntSize     szImageSize = dlg.GetSize() ;

		_nFilterIndex = dlg.m_ofn.nFilterIndex ;
		EImageFormat eFormat = (EImageFormat) arrFileFormats[dlg.m_ofn.nFilterIndex - 1] ;
		RRealSize pictureSize  = pComponentView->GetReferenceSize() ;

		try
		{
			if (kImageFormatXRX == eFormat)
			{
				RRealSize outputSize( szImageSize.m_dx, szImageSize.m_dy ) ; //   = pictureSize ;
				RRealSize screenDPI    = ::GetScreenDPI() ;

				RVectorImage vectorImage ;
				vectorImage.SetSuggestedWidthInInches( ::PixelsToInches( outputSize.m_dx, (uLONG) screenDPI.m_dx ) ) ;
				vectorImage.SetSuggestedHeightInInches( ::PixelsToInches( outputSize.m_dy, (uLONG) screenDPI.m_dy ) ) ;

				// Create an offscreen drawing surface and set the picture
				ROffscreenDrawingSurface drawingSurface;
				drawingSurface.SetImage( &vectorImage );

				R2dTransform transform ;

				// Scale to the device DPI
				RRealSize deviceDPI = drawingSurface.GetDPI( );
				transform.PreScale( (YFloatType) deviceDPI.m_dx / screenDPI.m_dy, 
					(YFloatType) deviceDPI.m_dy / screenDPI.m_dy );

				transform.PreScale( 
					outputSize.m_dx / pictureSize.m_dx,
					outputSize.m_dy / pictureSize.m_dy ) ;

				// Render the component
				RRealRect outputRect( pictureSize ) ;
				pComponentView->Render( drawingSurface, transform, outputRect ) ;

				drawingSurface.ReleaseImage( );

				rLibrary.ExportImage( vectorImage, strPathName, kImageFormatXRX ) ;
				if (rLibrary.GetLastException() != kNoError)
				{
					throw rLibrary.GetLastException() ;
				}
			} // if (XRX)
			else
			{
				// Check for a image interface
				RImageInterface* pInterface = (RImageInterface *) 
					pComponentView->GetInterface( kImageInterfaceId ) ;

				if (pInterface)
				{
					pInterface->Export( strPathName, eFormat ) ;
					delete pInterface ;
				}
				else
				{
					// Initialize the new bitmap at a bit depth of 24
					RBitmapImage image ;
					image.Initialize( szImageSize.m_dx, szImageSize.m_dy, 24 ) ;

					ROffscreenDrawingSurface dsMem ; 
					dsMem.SetImage( &image ) ;

					R2dTransform transform ;
					transform.PreScale( 
						szImageSize.m_dx / pictureSize.m_dx,
						szImageSize.m_dy / pictureSize.m_dy ) ;

					// Render the component
					dsMem.SetFillColor( RSolidColor( kWhite ) ) ;
					dsMem.FillRectangle( RRealRect( pictureSize ), transform ) ;
					pComponentView->Render( dsMem, transform, RIntRect( 
						RIntSize( pictureSize.m_dx, pictureSize.m_dy ) ) ) ;

					dsMem.ReleaseImage() ;
					
					rLibrary.ExportImage( image, strPathName, eFormat ) ;
				}

				if (rLibrary.GetLastException() != kNoError)
				{
					throw rLibrary.GetLastException() ;
				}
			
			} // else

		} // try

		catch( YException e)
		{
			ReportException( e ) ;
		}

	} // if (IDOK)
}