// **************************************************************************** // // 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; }
// **************************************************************************** // // Function Name: RBreakGroupAction::Do( ) // // Description: Does the action // // Returns: TRUE if the action was sucessful // // Exceptions: None // // **************************************************************************** // BOOLEAN RBreakGroupAction::Do( ) { // Call the base method to setup the state properly RUndoableAction::Do( ); // Get the group components view m_pGroupView = *m_pCurrentSelection->Start( ); // Unselect the group component m_pCurrentSelection->UnselectAll( ); RView* pParentView = m_pCurrentSelection->GetView( ); // Get the z-position of the group YComponentZPosition groupZPosition = pParentView->GetComponentZPosition( m_pGroupView ); // Remove the components from the group document YComponentIterator iterator = m_pGroupDocument->GetComponentCollectionStart( ); while( iterator != m_pGroupDocument->GetComponentCollectionEnd( ) ) { // Get the view that is in the group RComponentView* pView = dynamic_cast<RComponentView*>( (*iterator)->GetView( m_pGroupView ) ); TpsAssert( pView, "Not a component view." ); // Make a copy of the iterator, as we are going to delete it next YComponentIterator tempIterator = iterator; ++tempIterator; // Get the component document RComponentDocument* pComponent = *iterator; // Remove the component from the group m_pGroupDocument->RemoveComponent( pComponent ); // NULL out the views parent pView->SetParentView( NULL ); // Now add it to its original parent docuemnt m_pParentDocument->AddComponent( pComponent ); // Set the correct z-position pParentView->SetComponentZPosition( pComponent->GetView( pParentView ), groupZPosition ); // Increment the z-position for the next component groupZPosition++; // Move the view back to the coordinate space of its parent view YComponentBoundingRect temp = pView->GetBoundingRect( ); temp *= m_pGroupView->GetBoundingRect( ).GetTransform( ); pView->SetBoundingRect( temp ); // Select the component m_pCurrentSelection->Select( pView, TRUE ); // Reassign the iterator iterator = tempIterator; } // Remove the group component m_pParentDocument->RemoveComponent( m_pGroupDocument ); // Update the view that its layout has changed m_pCurrentSelection->GetView()->XUpdateAllViews( kLayoutChanged, 0 ); // Copy the selection so that we can undo m_OldSelection = *m_pCurrentSelection; return TRUE; }