// **************************************************************************** // // Function Name: RNameAddress::FormatNameAddress( ) // // Description: Perform the formatting described in the format string to // the given inputs and put the result into address // // Returns: Nothing // // Exceptions: kMemory // // **************************************************************************** // void RNameAddress::FormatNameAddress( RMergeFieldContainer& output, const RMBCString& format, YMergeId firstName, YMergeId lastName, YMergeId address, YMergeId city, YMergeId state, YMergeId zip, YMergeId country ) { output.Empty( ); RMBCStringIterator iterator = format.Start( ); RMBCStringIterator iteratorEnd = format.End( ); for ( ; iterator != iteratorEnd; ++iterator ) { RCharacter ch = ( *iterator ); if ( ch == kFormatIdentifierTag ) { ++iterator; TpsAssert( iterator!=iteratorEnd, "Format Identifier found at end of stream" ); ch = ( *iterator ); if ( ch == kFirstNameIdentifierTag ) output.InsertAtEnd( firstName ); else if ( ch == kLastNameIdentifierTag ) output.InsertAtEnd( lastName ); else if ( ch == kAddressIdentifierTag ) output.InsertAtEnd( address ); else if ( ch == kCityIdentifierTag ) output.InsertAtEnd( city ); else if ( ch == kStateIdentifierTag ) output.InsertAtEnd( state ); else if ( ch == kZipIdentifierTag ) output.InsertAtEnd( zip ); else if ( ch == kCountryIdentifierTag ) output.InsertAtEnd( country ); else { TpsAssertAlways( "Unknown format tag found" ); } } else { if ( ch == kSpaceTag ) output.InsertAtEnd( kMergeFieldSpace ); else if ( ch == kReturnTag ) output.InsertAtEnd( kMergeFieldReturn ); else if ( ch == kTabTag ) output.InsertAtEnd( kMergeFieldTab ); else if ( ch == kCommaTag ) output.InsertAtEnd( kMergeFieldComma ); else { TpsAssertAlways( "Unsupported Character, If it is necessary add it to the MergeField info and here" ); } } } }
// **************************************************************************** // // Function Name: RGraphicDateTimeInterfaceImp::SetDateTime( ) // // Description: // // Returns: // // Exceptions: // // **************************************************************************** void RGraphicDateTimeInterfaceImp::SetDateTime( const RDateTime& rDateTime, BOOLEAN ) { if (m_pTimepiece) m_pTimepiece->SetTime(rDateTime.GetTime()); else TpsAssertAlways("Graphic component does not contain a timepiece. An RDateTime interface should not have been returned."); }
// **************************************************************************** // // Function Name: RNameAddress::FormatNameAddress( ) // // Description: Perform the formatting described in the format string to // the given inputs and put the result into output // // Returns: Nothing // // Exceptions: kMemory // // **************************************************************************** // void RNameAddress::FormatNameAddress( RMBCString& output, const RMBCString& format, const RMBCString& firstName, const RMBCString& lastName, const RMBCString& address, const RMBCString& city, const RMBCString& state, const RMBCString& zip, const RMBCString& country ) { output.Empty( ); RMBCStringIterator iterator = format.Start( ); RMBCStringIterator iteratorEnd = format.End( ); for ( ; iterator != iteratorEnd; ++iterator ) { RCharacter ch = ( *iterator ); if ( ch == kFormatIdentifierTag ) { ++iterator; TpsAssert( iterator!=iteratorEnd, "Format Identifier found at end of stream" ); ch = ( *iterator ); if ( ch == kFormatIdentifierTag ) output += kFormatIdentifierTag; else if ( ch == kFirstNameIdentifierTag ) output += firstName; else if ( ch == kLastNameIdentifierTag ) output += lastName; else if ( ch == kAddressIdentifierTag ) output += address; else if ( ch == kCityIdentifierTag ) output += city; else if ( ch == kStateIdentifierTag ) output += state; else if ( ch == kZipIdentifierTag ) output += zip; else if ( ch == kCountryIdentifierTag ) output += country; else { TpsAssertAlways( "Unknown format tag found" ); } } else { if ( ch == kSpaceTag ) output += ch; else if ( ch == kReturnTag ) output += ch; else if ( ch == kTabTag ) output += ch; else if ( ch == kCommaTag ) output += ch; else { //TpsAssertAlways( "Unsupported Character, If it is necessary add it to the MergeField info and here" ); output += ch; } } } }
// **************************************************************************** // // Function Name: RGraphicDateTimeInterfaceImp::GetDateTime( ) // // Description: // // Returns: // // Exceptions: // // **************************************************************************** const RDateTime& RGraphicDateTimeInterfaceImp::GetDateTime( ) const { if (m_pTimepiece) const_cast<RDateTime&>(m_rDateTime).SetTime(m_pTimepiece->GetTime()); else TpsAssertAlways("Graphic component does not contain a timepiece. An RDateTime interface should not have been returned."); return m_rDateTime; }
// **************************************************************************** // // Function Name: RPathApplication::CreateNewDocument( ) // // Description: Creates a new document of the specified type // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // RComponentDocument* RPathApplication::CreateNewDocument( const RComponentAttributes& componentAttributes, const YComponentType& componentType, BOOLEAN fLoading ) { if (componentType == kPathComponent) { return new RPathDocument( this, componentAttributes, componentType, fLoading ); } else { TpsAssertAlways("Bad component type in RPathApplication::CreateNewDocument()."); return NULL; } }
// **************************************************************************** // // Function Name: RNumberDialog::GetSmartNumberSuffix // // Description: Return internationally correct suffix for given string // embedded number // // Returns: suffix // // Exceptions: None // // **************************************************************************** RMBCString RNumberDialog::GetSmartNumberSuffix( const RMBCString& rNumber ) { int nNumber = atoi( (LPCSZ)rNumber ); TpsAssert( nNumber >= 0 , "Number string invalid. Negative numbers not supported." ); TpsAssert( nNumber <= kMaxNumber, "Number string invalid. Too large."); TpsAssert( rNumber.GetStringLength() <= kMaxNumNumbers, "Number string too long" ); if( nNumber == 0 && rNumber.GetStringLength() > 1 ) { TpsAssertAlways( "Invalid number string." ); } // // Only interested in the last two digits of number (ie. Suffix for 12 is the // same as suffix for 112) int nMeaningfulDigits = atoi( (LPCSZ)rNumber ); if( rNumber.GetStringLength() > 2 ) { // If the number is three digits or greater, just get the last two digits.. char sDigitConvert[3]; //strncpy( sDigitConvert, (LPCSZ)rNumber[ rNumber.GetStringLength() - 2 ], 2 ); sDigitConvert[ 0 ] = rNumber[ rNumber.GetStringLength() - 2 ]; sDigitConvert[ 1 ] = rNumber[ rNumber.GetStringLength() - 1 ]; sDigitConvert[ 2 ] = 0; nMeaningfulDigits = atoi( sDigitConvert ); } // // To be safe for all languages we define suffixes for every number up to // 20, then just define suffixes for the second digit for numbers greater // than that. if( nMeaningfulDigits < kNumberOfSuffixesDefinedFromZero ) { /*!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ // Smart number ids from 0-19 MUST be sequential or the proper suffix will // NOT be used!!!!!! -MWH int nFirstSuffixInResource = IDS_SMARTNUM_SUFFIX_0; return ::GetResourceManager().GetResourceString( nFirstSuffixInResource + nMeaningfulDigits ); } else { // // Number is greater than 20, need to get last digit suffix RMBCString rLastDigit(""); rLastDigit += rNumber[rNumber.GetStringLength()-1]; int nLastDigit = atoi( (LPCSZ)rLastDigit ); /*!!!!!!!!!!!! NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ // Smart number two digit ids MUST be sequential or the proper suffix will // NOT be used!!!!!! -MWH int nFirst2DigitSuffixInResource = IDS_SMARTNUM_2DIGIT_SUFFIX_0; return ::GetResourceManager().GetResourceString( nFirst2DigitSuffixInResource + nLastDigit ); } }
void RBackdropSearchCollection::SetSearchCriteria( const RSearchCriteria* aSearchCriteria ) { RSearchCriteria* aNonConstSearchCriteria = const_cast<RSearchCriteria*>(aSearchCriteria); RBackdropSearchCriteria* aBackdropSearchCriteria = dynamic_cast<RBackdropSearchCriteria*>(aNonConstSearchCriteria); if (aBackdropSearchCriteria == NULL) { TpsAssertAlways( "A valid RBackdropSearchCriteria object is required." ); } else { theBackdropSearchCriteria = *aBackdropSearchCriteria; } }
// **************************************************************************** // // Function Name: RGpDrawingSurface::DeviceInvertPolygon( ) // // Description: Inverts a polygon // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RGpDrawingSurface::DeviceInvertPolygon( const RIntPoint* pPoints, YPointCount numPoints ) { PolyHandle hPoly; TpsAssert( ( numPoints < kMaxPoints ), "Too many points." ); if ( numPoints == 2 ) { TpsAssertAlways( "Cannot invert a 2point polygon" ); } else { hPoly = CreatePolygon( pPoints, numPoints ); ::InvertPoly( hPoly ); ::DisposeHandle( (Handle)hPoly ); } }
// **************************************************************************** // // Function Name: BitmapImageList::Render() // // Description: Renders the specified image onto the drawing // surface int the specified style. // // Returns: TRUE if successful; otherwise FALSE. // // Exceptions: None // // **************************************************************************** BOOLEAN RBitmapImageList::Render( RDrawingSurface& ds, int nImage, RIntRect rcDestRect, uLONG ulStyle ) { if ((uLONG) nImage < 0 || (uLONG) nImage > m_ulImageCount) { return FALSE ; } int nCols = GetWidthInPixels() / m_szImage.m_dx ; RIntSize szOffset( nImage % nCols * m_szImage.m_dx, nImage / nCols * m_szImage.m_dy ) ; RIntRect rcSrcRect( 0, 0, m_szImage.m_dx, m_szImage.m_dy ) ; rcSrcRect.Offset( szOffset ) ; if (!m_fMask) { // If there is no mask, the bitmap will always be drawn normal RBitmapImage::Render( ds, rcSrcRect, rcDestRect ) ; } else { // // Render the bitmap in the appropriate style // switch (ulStyle) { case kNormal: RBitmapImage::Render( ds, rcSrcRect, rcDestRect ) ; break ; case kTransparent: RBitmapImage::RenderWithMask( ds, m_bmMask, rcSrcRect, rcDestRect ) ; break ; default: TpsAssertAlways( "Not yet implemented!" ) ; } } return TRUE ; }
// **************************************************************************** // // Function Name: RAlert::AskUserForCdSwap( YResourceId DialogTemplate ) // // Description: Ask the user to insert a CD with OK and Cancel buttons. // The alert to use is specified by DialogTemplate. // // For 32-bit CD-ROM drivers, if a CD is inserted before OK is // clicked, the dialog automatically terminates and this // function returns kAlertOk. // // Returns: kAlertOk or kAlertCancel // // Exceptions: None // // **************************************************************************** // YAlertValues RAlert::AskUserForCdSwap( YResourceId DialogTemplate ) { RCdSwapDialog theDialog; if (!theDialog.InitModalIndirect( GetResourceManager().GetResourceDialogTemplate( DialogTemplate ) )) { TpsAssertAlways( "InitModalIndirect failed!" ); return kAlertCancel; // shouldn't happen } if (theDialog.DoModal() == IDOK) { // set wait cursor on assumption that it may take a little while for // calling code to open and search files on the CD and that someone else // will set the cursor back to normal later ::GetCursorManager().SetCursor( IDC_WAIT ); return kAlertOk; } else return kAlertCancel; }
// **************************************************************************** // // Function Name: RMFCCommandUI::GetDroppedState( ) // // Description: This function is for when the update must be for a // combobox. If the RMFCCommandUI object is a combobox or has // a child combobox, this checks the combobox to see if its // list box is dropped. // // Returns: TRUE: List box is dropped // FALSE: List box is not dropped // // Exceptions: None // // **************************************************************************** // BOOLEAN RMFCCommandUI::GetDroppedState( ) { TpsAssert( m_pCmdUI->m_pMenu == NULL, "CommandUI object is not a control" ); TpsAssert( m_pCmdUI->m_pOther, "m_pCmdUI->m_pOther is NULL" ); HWND hWnd = m_pCmdUI->m_pOther->GetSafeHwnd(); CWnd* pWnd = NULL; while ( hWnd ) { pWnd = pWnd->FromHandle( hWnd ); if ( pWnd->IsKindOf( RUNTIME_CLASS( CComboBox ) ) ) { CComboBox* pComboBox = ( CComboBox* )pWnd; return BOOLEAN( pComboBox->GetDroppedState() ); } else hWnd = ::GetWindow( hWnd, GW_CHILD ); } TpsAssertAlways( "RMFCCommandUI object is not a combobox" ); return FALSE; }
//***************************************************************************** // // Function Name: RGridCtrl::OnSetFocus(CWnd* pOldWnd) // // Description: Message handler for WM_SETFOCUS // // Returns: None // // Exceptions: None // //***************************************************************************** void RGridCtrlBase::OnSetFocus( CWnd* ) { if (::IsWindow( GetSafeHwnd() )) { CWnd* pParent = GetParent() ; if (pParent) { // Notify the parent that the grid control // is gaining the keyboard input focus. GetParent()->PostMessage( WM_COMMAND, MAKEWPARAM( GetDlgCtrlID(), LBN_SETFOCUS ), (LPARAM) m_hWnd ) ; } CClientDC dc(this) ; SendDrawItem( dc, max( GetCurSel(), 0 ), ODA_FOCUS ) ; } else { TpsAssertAlways( "Invalid Window Handle!" ) ; } }
// **************************************************************************** // // Function Name: RAlert::AskUserForGraphicBrowserCdSwap() // // Description: Ask the user to insert a CD with OK, Cancel and // Other Graphics buttons - suitable for use with bringing // up the graphics browser dialog. // // For 32-bit CD-ROM drivers, if a CD is inserted before OK is // clicked, the dialog automatically terminates and this // function returns kAlertOk. // // Returns: kGBAlertOk, kGBAlertCancel or kGBOtherGraphics // // Exceptions: None // // **************************************************************************** // YGBCDSwapAlertValues RAlert::AskUserForGraphicBrowserCdSwap() { RCdSwapDialog theDialog; if (!theDialog.InitModalIndirect( GetResourceManager().GetResourceDialogTemplate( DIALOG_CD_SWAP_GB ) )) { TpsAssertAlways( "InitModalIndirect failed!" ); return kGBAlertCancel; // shouldn't happen } int dialogStatus = theDialog.DoModal(); if (dialogStatus == IDOK) { // set wait cursor on assumption that it may take a little while for // calling code to open and search files on the CD and that someone else // will set the cursor back to normal later ::GetCursorManager().SetCursor( IDC_WAIT ); return kGBAlertOk; } else if (dialogStatus == kGBOtherGraphics) return kGBOtherGraphics; else return kGBAlertCancel; }
// **************************************************************************** // // Function Name: FindNextPoint() // // Description: Find next point while following outline based on direction. // // Returns: DIRECTION of next point (see enums at top of file) // // Exceptions: none // // **************************************************************************** static uBYTE FindNextPoint (const RIntPoint& LastPoint, RIntPoint& NextPoint, uBYTE Direction, const DIBINFO& Dib) { sLONG DibWidth = Dib.Width; sLONG DibHeight = Dib.Height; BOOLEAN PointFound = FALSE; sLONG PixelIndex; sLONG ThisRowIndex, NextRowIndex, PrevRowIndex; sLONG ThisColIndex, NextColIndex, PrevColIndex; uBYTE LoopCount = 0; uLONG BytesPerRow = Dib.BytesPerRow; //ByteAlign(DibWidth, Dib.BytesPerPixel); ThisRowIndex = LastPoint.m_y * BytesPerRow; NextRowIndex = ThisRowIndex + BytesPerRow; PrevRowIndex = ThisRowIndex - BytesPerRow; ThisColIndex = LastPoint.m_x * Dib.BytesPerPixel; NextColIndex = ThisColIndex + Dib.BytesPerPixel; PrevColIndex = ThisColIndex - Dib.BytesPerPixel; while (!PointFound) { switch (Direction) { case EAST: NextPoint.m_x = LastPoint.m_x + 1; NextPoint.m_y = LastPoint.m_y; PixelIndex = ThisRowIndex + NextColIndex; break; case N_EAST: NextPoint.m_x = LastPoint.m_x + 1; NextPoint.m_y = LastPoint.m_y + 1; PixelIndex = NextRowIndex + NextColIndex; break; case NORTH: NextPoint.m_x = LastPoint.m_x; NextPoint.m_y = LastPoint.m_y + 1; PixelIndex = NextRowIndex + ThisColIndex; break; case N_WEST: NextPoint.m_x = LastPoint.m_x - 1; NextPoint.m_y = LastPoint.m_y + 1; PixelIndex = NextRowIndex + PrevColIndex; break; case WEST: NextPoint.m_x = LastPoint.m_x - 1; NextPoint.m_y = LastPoint.m_y; PixelIndex = ThisRowIndex + PrevColIndex; break; case S_WEST: NextPoint.m_x = LastPoint.m_x - 1; NextPoint.m_y = LastPoint.m_y - 1; PixelIndex = PrevRowIndex + PrevColIndex; break; case SOUTH: NextPoint.m_x = LastPoint.m_x; NextPoint.m_y = LastPoint.m_y - 1; PixelIndex = PrevRowIndex + ThisColIndex; break; case S_EAST: NextPoint.m_x = LastPoint.m_x + 1; NextPoint.m_y = LastPoint.m_y - 1; PixelIndex = PrevRowIndex + NextColIndex; break; default: TpsAssertAlways("Bad case statement value"); break; } // If the point falls outside of the bitmap, change direction appropriately if ((NextPoint.m_x < 0) || (NextPoint.m_x > (sLONG) DibWidth - 1) || (NextPoint.m_y < 0) || (NextPoint.m_y > (sLONG) DibHeight - 1)) { Direction = (uBYTE)((--Direction) & 0x07); } else { LoopCount++; if (LoopCount > S_EAST) { // Only 1 pixel in this shape NextPoint = LastPoint; return NULL_DIRECTION; } //PixelIndex = NextPoint.y * BytesPerRow + NextPoint.x * Dib.BytesPerPixel; switch (Dib.BytesPerPixel) { case 1: if (Dib.pBits[PixelIndex] == (uBYTE) Dib.TransparentColor) { Direction = (uBYTE)((--Direction) & 0x07); } else { PointFound = TRUE; } break; case 2: if (*((uWORD*) &Dib.pBits[PixelIndex]) == (uWORD) Dib.TransparentColor) { Direction = (uBYTE)((--Direction) & 0x07); } else { PointFound = TRUE; } break; case 3: if ((*((uLONG*) &Dib.pBits[PixelIndex]) & 0x00FFFFFF) == Dib.TransparentColor) { Direction = (uBYTE)((--Direction) & 0x07); } else { PointFound = TRUE; } break; case 4: if (*((uLONG*) &Dib.pBits[PixelIndex]) == Dib.TransparentColor) { Direction = (uBYTE)((--Direction) & 0x07); } else { PointFound = TRUE; } break; default: TpsAssertAlways("Bad case statement value"); } } } return Direction; }
// **************************************************************************** // // Function Name: RSingleSelection::GetResizeSelectionHandle( ) // // Description: Retrieves a vector rect representing requested resize handle. // // Returns: Nothing // // Exceptions: Memory // // **************************************************************************** // void RSingleSelection::GetResizeSelectionHandle( RRealRect& rHandle, const R2dTransform& transform, EHitLocation eHit, BOOLEAN fRender ) const { RRealPoint point; YSelectionBoundingRect boundingRect; RIntSize outsetSize = (fRender)? RRealSize( kCornerResizeHandleRenderSize, kCornerResizeHandleRenderSize ) : RRealSize( kResizeHandleHitSize, kResizeHandleHitSize ); // Get the bounding rectangle GetSelectionBoundingRect( boundingRect ); // Get the proper point to transform switch ( eHit ) { case kLeftResizeHandle: ::midpoint( point, boundingRect.m_TopLeft, boundingRect.m_BottomLeft ); outsetSize.m_dx = Max( kEdgeResizeHandleRenderSize, YIntDimension(outsetSize.m_dx/2) ); break; case kTopResizeHandle: ::midpoint( point, boundingRect.m_TopLeft, boundingRect.m_TopRight ); outsetSize.m_dy = Max( kEdgeResizeHandleRenderSize, YIntDimension(outsetSize.m_dy/2) ); break; case kRightResizeHandle: ::midpoint( point, boundingRect.m_TopRight, boundingRect.m_BottomRight ); outsetSize.m_dx = Max( kEdgeResizeHandleRenderSize, YIntDimension(outsetSize.m_dx/2) ); break; case kBottomResizeHandle: ::midpoint( point, boundingRect.m_BottomLeft, boundingRect.m_BottomRight ); outsetSize.m_dy = Max( kEdgeResizeHandleRenderSize, YIntDimension(outsetSize.m_dy/2) ); break; case kTopLeftResizeHandle: point = boundingRect.m_TopLeft; break; case kTopRightResizeHandle: point = boundingRect.m_TopRight; break; case kBottomLeftResizeHandle: point = boundingRect.m_BottomLeft; break; case kBottomRightResizeHandle: point = boundingRect.m_BottomRight; break; default : TpsAssertAlways( "Asking for the selection handle of invalid type" ); point = boundingRect.GetCenterPoint(); } RIntSize halfOutset( outsetSize.m_dx/2, outsetSize.m_dy/2); ::LogicalUnitsToDeviceUnits( point, *m_pView ); rHandle.m_Left = point.m_x - halfOutset.m_dx; rHandle.m_Top = point.m_y - halfOutset.m_dy; rHandle.m_Right = point.m_x + outsetSize.m_dx - halfOutset.m_dx; rHandle.m_Bottom = point.m_y + outsetSize.m_dy - halfOutset.m_dy; ::DeviceUnitsToLogicalUnits( rHandle, *m_pView ); rHandle *= transform; }
// **************************************************************************** // // Function Name: RCompositeSelection::SetResizeCursor( ) // // Description: Calculates which resize cursor to use, and sets it // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RCompositeSelection::SetResizeCursor( RSingleSelection* pHitObject, EHitLocation eHitLocation ) const { // Get the center point of the object YComponentBoundingRect boundingRect; pHitObject->GetObjectBoundingRect( boundingRect ); RRealPoint centerPoint = boundingRect.GetCenterPoint( ); // Create a new bounding rect that is a square. YComponentBoundingRect squareRect = boundingRect; RRealSize size = squareRect.WidthHeight( ); if( size.m_dx > size.m_dy ) squareRect.UnrotateAndScaleAboutPoint( centerPoint, RRealSize( size.m_dy / size.m_dx, 1.0 ) ); else squareRect.UnrotateAndScaleAboutPoint( centerPoint, RRealSize( 1.0, size.m_dx / size.m_dy ) ); // Select a point from this square based on the hit location RRealPoint point; switch( eHitLocation ) { case kLeftResizeHandle : ::midpoint( point, squareRect.m_TopLeft,squareRect.m_BottomLeft); break; case kTopResizeHandle : ::midpoint( point, squareRect.m_TopLeft,squareRect.m_TopRight); break; case kRightResizeHandle : ::midpoint( point, squareRect.m_TopRight,squareRect.m_BottomRight); break; case kBottomResizeHandle : ::midpoint( point, squareRect.m_BottomLeft,squareRect.m_BottomRight); break; case kTopLeftResizeHandle : point = squareRect.m_TopLeft; break; case kTopRightResizeHandle : point = squareRect.m_TopRight; break; case kBottomLeftResizeHandle : point = squareRect.m_BottomLeft; break; case kBottomRightResizeHandle : point = squareRect.m_BottomRight; break; default : TpsAssertAlways( "Invalid hit location in RCompositeSelection::SetResizeCursor( )." ); } // Calculate the angle between a vertical line through the square center and // a line connecting the calculatated point and the square center. YAngle angle = ::atan2( (YFloatType)( point.m_x - centerPoint.m_x ), (YFloatType)( centerPoint.m_y - point.m_y ) ); // atan2 returns an angle between PI and -PI. Convert this to an angle between 0 and 2PI if( angle < 0 ) angle += ( 2 * kPI ); // Select a cursor. We have 4 cursors to choose from, rotated in 45 degree // increments. Divide the angle by 45 deg. and use the resulting octant // number mod 4 to index into an array of cursor ids. int nOctant = ::Round( angle / ( kPI / 4 ) ); TpsAssert( nOctant >= 0 && nOctant <= 8, "Invalid octant." ); #ifdef _WINDOWS static LPCTSTR cursorArray[ 4 ] = { IDC_SIZENS, IDC_SIZENESW, IDC_SIZEWE, IDC_SIZENWSE }; #else // REVIEW: define cursors for Mac #endif // Set the cursor ::GetCursorManager( ).SetCursor( cursorArray[ nOctant % 4 ] ); }
// **************************************************************************** // // Function Name: RSolidColor::RSolidColor( ) // // Description: Constructor // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // RSolidColor::RSolidColor( EColors eColor ) { switch ( eColor ) { #ifdef _WINDOWS case kBlack : m_Color = RGB( 0x00, 0x00, 0x00 ); break; case kWhite : m_Color = RGB( 0xFF, 0xFF, 0xFF ); break; case kYellow : m_Color = RGB( 0xFF, 0xFF, 0 ); break; case kMagenta : m_Color = RGB( 0xFF, 0, 0xFF ); break; case kRed : m_Color = RGB( 0xFF, 0, 0 ); break; case kCyan : m_Color = RGB( 0, 0xFF, 0xFF ); break; case kGreen : m_Color = RGB( 0, 0xFF, 0 ); break; case kBlue : m_Color = RGB( 0, 0, 0xFF ); break; case kGray : m_Color = RGB( 0x80, 0x80, 0x80 ); break; case kLightGray : m_Color = RGB( 0xC0, 0xC0, 0xC0 ); break; case kDarkGray : m_Color = RGB( 0x40, 0x40, 0x40 ); break; #endif // _WINDOWS #ifdef MAC case kBlack : m_Color.red = 0x0000; m_Color.green = 0x0000; m_Color.blue = 0x0000; break; case kWhite : m_Color.red = 0xFFFF; m_Color.green = 0xFFFF; m_Color.blue = 0xFFFF; break; case kYellow : m_Color.red = 0xFC00; m_Color.green = 0xF37D; m_Color.blue = 0x052F; break; case kMagenta : m_Color.red = 0xF2D7; m_Color.green = 0x0856; m_Color.blue = 0x84EC; break; case kRed : m_Color.red = 0xDD6B; m_Color.green = 0x08C2; m_Color.blue = 0x06A2; break; case kCyan : m_Color.red = 0x0241; m_Color.green = 0xAB54; m_Color.blue = 0xEAFF; break; case kGreen : m_Color.red = 0x0000; m_Color.green = 0x8000; m_Color.blue = 0x11B0; break; case kBlue : m_Color.red = 0x0000; m_Color.green = 0x0000; m_Color.blue = 0xD400; break; case kGray : m_Color.red = 0x8080; m_Color.green = 0x8080; m_Color.blue = 0x8080; break; case kLightGray : m_Color.red = 0xC0C0; m_Color.green = 0xC0C0; m_Color.blue = 0xC0C0; break; case kDarkGray : m_Color.red = 0x4040; m_Color.green = 0x4040; m_Color.blue = 0x4040; break; #endif // MAC default : TpsAssertAlways( "Unrecognized color type." ); break; } }
// **************************************************************************** // // Function Name: RGpDrawingSurface::BlitDrawingSurface( ) // // Description: Copy from one the given drawing surface to this one // // Returns: Nothing // // Exceptions: None // // **************************************************************************** void RGpDrawingSurface::BlitDrawingSurface( const RDrawingSurface& rSrcDS, RIntRect rSrcRect, RIntRect rDestRect, EBlitMode eBlitMode ) { short mode; Rect srcRect, destRect; GrafPtr pSrcGrafPort, pDestGrafPort; GrafPtr savePort; RGBColor whiteColor, blackColor, foreColor, backColor; TpsAssertValid( this ); TpsAssertIsObject( RGpDrawingSurface, this ); TpsAssertIsObject(RGpDrawingSurface, &rSrcDS); pSrcGrafPort = (GrafPtr)rSrcDS.GetSurface(); pDestGrafPort = (GrafPtr)GetSurface(); TpsAssert( ( pSrcGrafPort != NULL ), "Source device is nil."); TpsAssert( ( pDestGrafPort != NULL ), "Destination device is nil."); // Set the port to the dest port GetPort(&savePort); SetPort(pDestGrafPort); switch ( eBlitMode ) { case kBlitSourceCopy : mode = srcCopy; break; case kBlitSourceAnd : mode = srcBic; break; case kBlitSourcePaint : mode = srcOr; break; case kBlitNotSourceAnd : mode = notSrcBic; break; case kBlitMergePaint : mode = notSrcOr; break; case kBlitSourceErase : default: TpsAssertAlways( "Invalid blit mode" ); break; } ::SetRect( &srcRect, rSrcRect.m_Left, rSrcRect.m_Top, rSrcRect.m_Right, rSrcRect.m_Bottom ); ::SetRect( &destRect, rDestRect.m_Left, rDestRect.m_Top, rDestRect.m_Right, rDestRect.m_Bottom ); ::GetBackColor( &backColor ); ::GetForeColor( &foreColor ); whiteColor.red = 0xFFFF; whiteColor.green = 0xFFFF; whiteColor.blue = 0xFFFF; blackColor.red = 0x0000; blackColor.green = 0x0000; blackColor.blue = 0x0000; ::RGBForeColor( &blackColor ); ::RGBBackColor( &whiteColor ); ::CopyBits( &(pSrcGrafPort->portBits), &(pDestGrafPort->portBits), &srcRect, &destRect, mode, nil ); ::RGBForeColor( &foreColor ); ::RGBBackColor( &backColor ); // Restore the saved port SetPort(savePort); }
// **************************************************************************** // // Function Name: RStandaloneDocument::Print( ) // // Description: Prints the document // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RStandaloneDocument::Print( RCancelPrintingSignal* ) { TpsAssertAlways( "No default printing code." ); }
// **************************************************************************** // // Function Name: RStandaloneDocument::PreparePrinting( ) // // Description: Displays a print dialog and prepares this document for // printing. // // Returns: TRUE if printing should continue // // Exceptions: None // // **************************************************************************** // BOOLEAN RStandaloneDocument::PreparePrinting( ) { TpsAssertAlways( "No default printing code." ); return FALSE; }
// **************************************************************************** // // Function Name: FindFirstEdge() // // Description: Find first non-transparent pixel in a DIB from ORIENTATION. // // Returns: TRUE if found, return in StartPoint // // Exceptions: none // // **************************************************************************** BOOLEAN FindFirstEdge (RIntPoint& StartPoint, const DIBINFO& Dib, const ORIENTATION FromWhere, const sLONG StartAt) { sLONG DibWidth = Dib.Width; sLONG DibHeight = Dib.Height; sLONG Index; uLONG BytesPerRow = Dib.BytesPerRow; _AssertDIBInfo(Dib); switch (FromWhere) { case LEFT: Index = StartPoint.m_y * BytesPerRow + StartAt * Dib.BytesPerPixel; for (StartPoint.m_x = 0; StartPoint.m_x < DibWidth; StartPoint.m_x++) { switch (Dib.BytesPerPixel) { case 1: if (Dib.pBits[Index] != (uBYTE) Dib.TransparentColor) return TRUE; break; case 2: if (*((uWORD*) &Dib.pBits[Index]) != (uWORD) Dib.TransparentColor) return TRUE; break; case 3: if ((*((uLONG*) &Dib.pBits[Index]) & 0x00FFFFFF) != Dib.TransparentColor) return TRUE; break; case 4: if (*((uLONG*) &Dib.pBits[Index]) != Dib.TransparentColor) return TRUE; break; default: TpsAssertAlways("Bad case statement value"); } Index += Dib.BytesPerPixel; } break; case RIGHT: Index = StartPoint.m_y * BytesPerRow + StartAt * Dib.BytesPerPixel; for (StartPoint.m_x = DibWidth - 1; StartPoint.m_x >= 0; StartPoint.m_x--) { switch (Dib.BytesPerPixel) { case 1: if (Dib.pBits[Index] != (uBYTE) Dib.TransparentColor) return TRUE; break; case 2: if (*((uWORD*) &Dib.pBits[Index]) != (uWORD) Dib.TransparentColor) return TRUE; break; case 3: if ((*((uLONG*) &Dib.pBits[Index]) & 0x00FFFFFF) != Dib.TransparentColor) return TRUE; break; case 4: if (*((uLONG*) &Dib.pBits[Index]) != Dib.TransparentColor) return TRUE; break; default: TpsAssertAlways("Bad case statement value"); } Index -= Dib.BytesPerPixel; } break; case TOP: Index = (StartAt) * BytesPerRow + StartPoint.m_x * Dib.BytesPerPixel; for (StartPoint.m_y = StartAt; StartPoint.m_y >= 0; StartPoint.m_y--) { switch (Dib.BytesPerPixel) { case 1: if (Dib.pBits[Index] != (uBYTE) Dib.TransparentColor) return TRUE; break; case 2: if (*((uWORD*) &Dib.pBits[Index]) != (uWORD) Dib.TransparentColor) return TRUE; break; case 3: if ((*((uLONG*) &Dib.pBits[Index]) & 0x00FFFFFF) != Dib.TransparentColor) return TRUE; break; case 4: if (*((uLONG*) &Dib.pBits[Index]) != Dib.TransparentColor) return TRUE; break; default: TpsAssertAlways("Bad case statement value"); } Index -= BytesPerRow; } break; case BOTTOM: Index = (StartAt) * BytesPerRow + StartPoint.m_x * Dib.BytesPerPixel; for (StartPoint.m_y = StartAt; StartPoint.m_y < DibHeight; StartPoint.m_y++) { switch (Dib.BytesPerPixel) { case 1: if (Dib.pBits[Index] != (uBYTE) Dib.TransparentColor) return TRUE; break; case 2: if (*((uWORD*) &Dib.pBits[Index]) != (uWORD) Dib.TransparentColor) return TRUE; break; case 3: if ((*((uLONG*) &Dib.pBits[Index]) & 0x00FFFFFF) != Dib.TransparentColor) return TRUE; break; case 4: if (*((uLONG*) &Dib.pBits[Index]) != Dib.TransparentColor) return TRUE; break; default: TpsAssertAlways("Bad case statement value"); } Index += BytesPerRow; } break; } return FALSE; }
// **************************************************************************** // // Function Name: RTrueTypeFont::GetGlyphOutline( ) // // Description: // // Returns: Nothing // // Exceptions: Memory, Font // // **************************************************************************** // void RTrueTypeFont::GetGlyphOutline( Handle sfnt, long glyphIndex, GlyphOutline* pOutline, Matrix xform ) { short state = GetFontState( sfnt ); short upem, sideBearing, adjustToLsb; short* glyph; sfnt_FontHeader* head; sfnt_HorizontalHeader* hhea; sfnt_HorizontalMetrics* hori; long length; long longMetrics; try { ::HLock( sfnt ); head = (sfnt_FontHeader *)GetSfntTablePtr( sfnt, tag_FontHeader ); hhea = (sfnt_HorizontalHeader *)GetSfntTablePtr( sfnt, tag_HoriHeader ); hori = (sfnt_HorizontalMetrics *)GetSfntTablePtr( sfnt, tag_HorizontalMetrics ); if ( head == NULL || hhea == NULL || hori == NULL ) throw fontNotOutlineErr; upem = head->unitsPerEm; longMetrics = hhea->numberLongMetrics; if ( glyphIndex < longMetrics ) { pOutline->advance.x = ::FixRatio( hori[glyphIndex].advance, upem ); sideBearing = hori[glyphIndex].sideBearing; } else { short *lsb = (short *)&hori[longMetrics]; // first entry after[AW,LSB] array pOutline->advance.x = ::FixRatio( hori[longMetrics-1].advance, upem ); sideBearing = hori[glyphIndex - longMetrics].sideBearing; } pOutline->advance.y = 0; pOutline->origin.x = pOutline->origin.y = 0; if ( (glyph = (short *)GetSfntGlyphPtr(sfnt, glyphIndex, &length)) == 0 ) throw fontNotOutlineErr; if ( length == 0 ) { pOutline->contourCount = pOutline->pointCount = 0; SetFontState( sfnt, state ); return; } pOutline->contourCount = *glyph++; adjustToLsb = *glyph - sideBearing; // xmin - lsb glyph += 4; // skip bounds rect if ( pOutline->contourCount == 0 ) pOutline->pointCount = 0; else if ( pOutline->contourCount == -1 ) { short flags, index, newMatrix; pOutline->contourCount = pOutline->pointCount = 0; mySetHandleSize( (Handle)pOutline->endPoints, 0 ); mySetHandleSize( (Handle)pOutline->onCurve, 0 ); mySetHandleSize( (Handle)pOutline->x, 0 ); mySetHandleSize( (Handle)pOutline->y, 0 ); do { Matrix compXform; short arg1, arg2; flags = *glyph++; index = *glyph++; newMatrix = false; if ( flags & ARG_1_AND_2_ARE_WORDS ) { arg1 = *glyph++; arg2 = *glyph++; } else { char* byteP = (char*)glyph; if ( flags & ARGS_ARE_XY_VALUES ) { // offsets are signed arg1 = *byteP++; arg2 = *byteP; } else { // anchor points are unsigned arg1 = (unsigned char)*byteP++; arg2 = (unsigned char)*byteP; } ++glyph; } #if IMPLEMENT_SCALED_COMPONENTS if ( flags & (WE_HAVE_A_SCALE | WE_HAVE_AN_X_AND_Y_SCALE | WE_HAVE_A_TWO_BY_TWO) ) { Matrix subXform; MakeIdentityMatrix( subXform ); if ( flags & WE_HAVE_A_TWO_BY_TWO ) { compXform[0][0] = (Fixed)*glyph++ << 2; compXform[0][1] = (Fixed)*glyph++ << 2; compXform[1][0] = (Fixed)*glyph++ << 2; compXform[1][1] = (Fixed)*glyph++ << 2; } else if ( flags & WE_HAVE_AN_X_AND_Y_SCALE ) { compXform[0][0] = (Fixed)*glyph++ << 2; compXform[1][1] = (Fixed)*glyph++ << 2; } else compXform[0][0] = compXform[1][1] = (Fixed)*glyph++ << 2; PostMulMatrix (compXform, xform ); newMatrix = true; } #endif { GlyphOutline out; InitGlyphOutline( &out ); GetGlyphOutline( sfnt, index, &out, newMatrix ? compXform : xform ); { Fixed dx, dy; if ( flags & ARGS_ARE_XY_VALUES ) { dx = ::FixRatio(arg1, upem); dy = -::FixRatio(arg2, upem); } else { dx = (*pOutline->x)[arg1] - (*out.x)[arg2]; dy = (*pOutline->y)[arg1] - (*out.y)[arg2]; } MoveGlyphOutline( &out, dx, dy ); } AppendGlyphOutline( pOutline, &out ); KillGlyphOutline( &out ); } } while ( flags & MORE_COMPONENTS ); } else if ( pOutline->contourCount > 0 ) { // Load in the end points. { long size = pOutline->contourCount * sizeof(short); mySetHandleSize( (Handle)pOutline->endPoints, size ); BlockMove( (Ptr)glyph, (Ptr)*pOutline->endPoints, size ); glyph += pOutline->contourCount; } pOutline->pointCount = (*pOutline->endPoints)[pOutline->contourCount - 1] + 1; mySetHandleSize( (Handle)pOutline->onCurve, pOutline->pointCount * sizeof(char) ); mySetHandleSize( (Handle)pOutline->x, pOutline->pointCount * sizeof(Fixed) ); mySetHandleSize( (Handle)pOutline->y, pOutline->pointCount * sizeof(Fixed) ); // Skip the word for instruction count + the instructions. // Then load in the onCurve bytes. { Byte* p = (Byte*)glyph + sizeof(short) + *glyph; Byte* onCurve = *pOutline->onCurve; Byte* stop = onCurve + pOutline->pointCount; Byte flag; while ( onCurve < stop ) { *onCurve++ = flag = GetUnsignedByte( p ); if ( flag & REPEAT_FLAGS ) { short count = GetUnsignedByte( p ); for ( --count; count >= 0; --count ) *onCurve++ = flag; } } // Lets do X { short coord = adjustToLsb; Fixed* x = *pOutline->x; onCurve = *pOutline->onCurve; while ( onCurve < stop ) { if ( (flag = *onCurve++) & XSHORT ) { if ( flag & SHORT_X_IS_POS ) coord += GetUnsignedByte( p ); else coord -= GetUnsignedByte( p ); } else if ( !(flag & NEXT_X_IS_ZERO) ) { coord += (short)(*p++) << 8; coord += (Byte)*p++; } *x = ::FixRatio( coord, upem ); x++; } } // Lets do Y { short coord = 0; Fixed* y = *pOutline->y; onCurve = *pOutline->onCurve; while ( onCurve < stop ) { if ( (flag = *onCurve) & YSHORT ) { if ( flag & SHORT_Y_IS_POS ) coord += GetUnsignedByte( p ); else coord -= GetUnsignedByte( p ); } else if ( !(flag & NEXT_Y_IS_ZERO) ) { coord += (short)(*p++) << 8; coord += (Byte)*p++; } *y = -::FixRatio( coord, upem ); y++; // Filter off the extra bits *onCurve++ = flag & ONCURVE; } } } } else throw fontNotOutlineErr; } catch ( OSErr osErr ) { SetFontState( sfnt, state ); switch ( osErr ) { case memFullErr : // out of memeory SetFontState( sfnt, state ); throw kMemory; break; case fontNotOutlineErr : // bad font SetFontState( sfnt, state ); throw kResource; break; default: TpsAssertAlways( "Bad exception" ); throw; break; } } catch ( ... ) { SetFontState( sfnt, state ); throw; } SetFontState( sfnt, state ); }