📄 diagramentitycontainer.cpp
字号:
int index = Find( obj );
if( index != -1 )
{
CDiagramEntity* newobj = obj->Clone();
newobj->SetRect( newobj->GetLeft() + 10, newobj->GetTop() + 10, newobj->GetRight() + 10, newobj->GetBottom() + 10 );
Add( newobj );
}
}
void CDiagramEntityContainer::Cut( CDiagramEntity* obj )
/* ============================================================
Function : CDiagramEntityContainer::Cut
Description : Cuts out the object and puts it into the
'clipboard'
Access : Public
Return : void
Parameters : CDiagramEntity* obj - The object to cut.
Usage : Call in response to a Cut-command. See also
the functions for copy/paste below.
============================================================*/
{
Copy( obj );
Remove( obj );
}
void CDiagramEntityContainer::Copy( CDiagramEntity* obj )
/* ============================================================
Function : CDiagramEntityContainer::Copy
Description : Copies the object to the 'clipboard'.
Access : Public
Return : void
Parameters : CDiagramEntity* obj - The object to copy.
Usage : Call in response to a Copy-command. Note
that obj will only be copied to the
clipboard, not the screen. See also the
functions for copy/paste below.
============================================================*/
{
ASSERT( obj );
if( m_clip == NULL )
m_clip = &m_internalClip;
if( obj )
m_clip->Copy( obj );
}
void CDiagramEntityContainer::Up( CDiagramEntity* obj )
/* ============================================================
Function : CDiagramEntityContainer::Up
Description : Moves the object one step up in the z-
order.
Access : Public
Return : void
Parameters : CDiagramEntity* obj - The object to move.
Usage : Call to move "obj" in the z-order.
============================================================*/
{
int index = Find( obj );
Swap( index, index + 1);
}
void CDiagramEntityContainer::Down( CDiagramEntity* obj )
/* ============================================================
Function : CDiagramEntityContainer::Down
Description : Moves the object one step down in the z-
order.
Access : Public
Return : void
Parameters : CDiagramEntity* obj - The object to move.
Usage : Call to move "obj" in the z-order.
============================================================*/
{
int index = Find( obj );
Swap( index, index - 1);
}
void CDiagramEntityContainer::Front( CDiagramEntity* obj )
/* ============================================================
Function : CDiagramEntityContainer::Front
Description : Moves "obj" to the top of the z-order.
Access : Public
Return : void
Parameters : CDiagramEntity* obj - The object to move.
Usage : Call to move "obj" in the z-order.
============================================================*/
{
int index = Find( obj );
m_objs.RemoveAt( index );
m_objs.Add( obj );
SetModified( TRUE );
}
void CDiagramEntityContainer::Bottom( CDiagramEntity* obj )
/* ============================================================
Function : CDiagramEntityContainer::Bottom
Description : Moves "obj" to the bottom of the z-order.
Access : Public
Return : void
Parameters : CDiagramEntity* obj - The object to move.
Usage : Call to move "obj" in the z-order.
============================================================*/
{
int index = Find( obj );
m_objs.RemoveAt( index );
m_objs.InsertAt( 0, obj );
SetModified( TRUE );
}
/////////////////////////////////////////////////////////////////////////////
// CDiagramEntityContainer copy/paste is implemented as separate class.
void CDiagramEntityContainer::SetClipboardHandler( CDiagramClipboardHandler* clip )
/* ============================================================
Function : CDiagramEntityContainer::SetClipboardHandler
Description : Sets the container clipboard class.
Access : Public
Return : void
Parameters : CDiagramClipboardHandler* clip - A pointer
to the
class
Usage : Call to set the clipboard handler for this
container. The same clipboard handler
instance can be used for several containers
to allow several editors (in an MDI-
application) to share the same clipboard.
============================================================*/
{
m_clip = clip;
}
CDiagramClipboardHandler* CDiagramEntityContainer::GetClipboardHandler()
/* ============================================================
Function : CDiagramEntityContainer::GetClipboardHandler
Description : Returns a pointer to the current clipboard
handler.
Access : Public
Return : CDiagramClipboardHandler* - Current handler.
Parameters : none
Usage : Call to get a pointer to the current handler.
============================================================*/
{
return m_clip;
}
void CDiagramEntityContainer::CopyAllSelected()
/* ============================================================
Function : CDiagramEntityContainer::CopyAllSelected
Description : Clones all selected object to the paste
array.
Access : Public
Return : void
Parameters : none
Usage : Call to copy all selected objects to the
clipboard. "Paste" will put them on screen.
============================================================*/
{
if( m_clip == NULL )
m_clip = &m_internalClip;
m_clip->CopyAllSelected( this );
}
int CDiagramEntityContainer::ObjectsInPaste()
/* ============================================================
Function : CDiagramEntityContainer::ObjectsInPaste
Description : Returns the number of objects in the paste
array.
Access : Public
Return : int - The number of objects.
Parameters : none
Usage : Call to get the number of objects in the
clipboard.
============================================================*/
{
if( m_clip == NULL )
m_clip = &m_internalClip;
return m_clip->ObjectsInPaste();
}
void CDiagramEntityContainer::ClearPaste()
/* ============================================================
Function : CDiagramEntityContainer::ClearPaste
Description : Clears the paste-array.
Access : Public
Return : void
Parameters : none
Usage : Call to clear the clipboard. All memory is
released.
============================================================*/
{
if( m_clip == NULL )
m_clip = &m_internalClip;
m_clip->ClearPaste();
}
void CDiagramEntityContainer::Paste()
/* ============================================================
Function : CDiagramEntityContainer::Paste
Description : Clones the contents of the paste array
into the container data array.
Access : Public
Return : void
Parameters : none
Usage : Call to paste the contents of the clipboard
to screen.
============================================================*/
{
if( m_clip == NULL )
m_clip = &m_internalClip;
m_clip->Paste( this );
}
/////////////////////////////////////////////////////////////////////////////
// CDiagramEntityContainer message handling
void CDiagramEntityContainer::SendMessageToObjects( int command, BOOL selected, CDiagramEntity* sender, CWnd* from, BOOL dirty )
/* ============================================================
Function : CDiagramEntityContainer::SendMessageToObjects
Description : Sends "command" to objects.
Access : Public
Return : void
Parameters : int command - The command to send.
BOOL selected - If "TRUE", the command
will only be sent to
selected objects,
otherwise, it will be
sent to all objects.
CDiagramEntity* sender - Original sender
or "NULL" if not
an object.
CWnd* from - Window of sender
BOOL dirty - If "TRUE", set the document
as dirty
Usage : Call this member to send messages to
(selected) objects in the range "CMD_START"
to "CMD_END" inclusively (defined in
DiagramEntity.h). Calls the object "DoCommand".
============================================================*/
{
BOOL stop = FALSE;
int max = m_objs.GetSize();
for( int t = 0 ; t < max ; t++ )
{
CDiagramEntity* obj = GetAt( t );
if( !stop && ( !selected || obj->IsSelected() ) )
{
stop = obj->DoMessage( command, sender, from );
if( dirty )
SetModified( TRUE );
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CDiagramEntityContainer private helpers
int CDiagramEntityContainer::Find( CDiagramEntity* testobj )
/* ============================================================
Function : CDiagramEntityContainer::Find
Description : Finds the index of object "testobj" in the
data array.
Access : Protected
Return : int - Index of the
object or -1
if not found.
Parameters : CDiagramEntity* testobj - Object to find.
Usage : Internal function.
============================================================*/
{
int index = -1;
CDiagramEntity* obj;
int count = 0;
while( ( obj = GetAt( count ) ) )
{
if( obj == testobj )
index = count;
count++;
}
return index;
}
void CDiagramEntityContainer::Swap( int index1, int index2 )
/* ============================================================
Function : CDiagramEntityContainer::Swap
Description : Swaps the elements at "index1" and "index2".
Access : Private
Return : void
Parameters : int index1 - First object to swap
int index2 - Second object to swap
Usage : Internal function. Used to move objects up
or down in the z-order.
============================================================*/
{
int max = m_objs.GetSize();
if( index1 >= 0 && index1 < max && index2 >= 0 && index2 < max )
{
CDiagramEntity* obj1 = GetAt( index1 );
CDiagramEntity* obj2 = GetAt( index2 );
SetAt( index1, obj2 );
SetAt( index2, obj1 );
}
}
void CDiagramEntityContainer::Undo()
/* ============================================================
Function : CDiagramEntityContainer::Undo
Description : Sets the container data to the last entry
in the undo stack.
Access : Public
Return : void
Parameters : none
Usage : Call to undo the last operation
============================================================*/
{
AddCurrentToStack( m_redo );
GetCurrentFromStack( m_undo );
}
void CDiagramEntityContainer::Redo()
/* ============================================================
Function : CDiagramEntityContainer::Redo
Description : Increases the undo-stack index and sets the
container data to the undo stack data at
this position.
Access : Public
Return : void
Parameters : none
Usage : Call to redo the last undo
============================================================*/
{
AddCurrentToStack( m_undo );
GetCurrentFromStack( m_redo );
}
void CDiagramEntityContainer::Snapshot()
/* ============================================================
Function : CDiagramEntityContainer::Snapshot
Description : Copies the current state of the data to
the undo-stack.
Access : Public
Return : void
Parameters : none
Usage : Call to add the current state to the undo-stack.
If the undo stack has a maximum size and
the stack will grow above the stack limit,
the first undo array will be removed.
============================================================*/
{
if( GetUndoStackSize() != 0 )
{
ClearRedo();
if( GetUndoStackSize() > 0 && m_undo.GetSize() == GetUndoStackSize() )
{
delete m_undo.GetAt( 0 );
m_undo.RemoveAt( 0 );
}
AddCurrentToStack( m_undo );
}
}
void CDiagramEntityContainer::GetCurrentFromStack( CObArray& arr )
/* ============================================================
Function : CDiagramEntityContainer::GetCurrentFromStack
Description : Sets the current objects from "arr".
Access : Private
Return : void
Parameters : CObArray& arr - Array to add current
object state from
Usage : Called to get the current object state from
"arr"
============================================================*/
{
if( arr.GetSize() )
{
// We remove all current data
RemoveAll();
// We get the entry from the undo-stack
// and clone it into the container data
CUndoItem* item = static_cast< CUndoItem* >( arr.GetAt( arr.GetUpperBound() ) );
if( item )
{
int count = ( item->arr ).GetSize();
for( int t = 0 ; t < count ; t++ )
{
CDiagramEntity* obj = static_cast< CDiagramEntity* >( ( item->arr ).GetAt( t ) );
Add( obj->Clone() );
}
// Set the saved virtual size as well
SetVirtualSize( item->pt );
delete item;
arr.RemoveAt( arr.GetUpperBound() );
}
}
}
void CDiagramEntityContainer::AddCurrentToStack( CObArray& arr )
/* ============================================================
Function : CDiagramEntityContainer::AddCurrentToStack
Description : Adds the current objects to "arr".
Access : Private
Return : void
Parameters : CObArray& arr - Array to add current
object state to
Usage : Called to add the current object state to
"arr"
============================================================*/
{
if( GetUndoStackSize() )
{
CUndoItem* item = new CUndoItem;
while( !item && arr.GetSize() )
{
// We seem - however unlikely -
// to be out of memory.
// Remove first element in
// the stack and try again
delete arr.GetAt( 0 );
arr.RemoveAt( 0 );
item = new CUndoItem;
}
if( item )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -