office-gobmx/soldep/source/connctr.cxx

280 lines
7.7 KiB
C++
Raw Normal View History

2004-02-26 07:51:54 -06:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2004-02-26 07:51:54 -06:00
*
* Copyright 2008 by Sun Microsystems, Inc.
2004-02-26 07:51:54 -06:00
*
* OpenOffice.org - a multi-platform office productivity suite
2004-02-26 07:51:54 -06:00
*
* $RCSfile: connctr.cxx,v $
* $Revision: 1.6 $
2004-02-26 07:51:54 -06:00
*
* This file is part of OpenOffice.org.
2004-02-26 07:51:54 -06:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2004-02-26 07:51:54 -06:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2004-02-26 07:51:54 -06:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2004-02-26 07:51:54 -06:00
*
************************************************************************/
#ifdef _MSC_VER
#pragma warning(disable:4100)
#endif
#include <soldep/connctr.hxx>
#include <soldep/objwin.hxx>
#include <soldep/depwin.hxx>
2004-02-26 07:51:54 -06:00
#include "math.h"
2006-04-20 09:16:35 -05:00
BOOL Connector::msbHideMode = FALSE;
2004-02-26 07:51:54 -06:00
Connector::Connector( DepWin* pParent, WinBits nWinStyle ) :
mpStartWin( 0L ),
mpEndWin( 0L ),
mnStartId( 0 ),
mnEndId( 0 ),
bVisible( FALSE ),
len( 70 )
2004-02-26 07:51:54 -06:00
{
mpParent = pParent;
if ( mpParent )
mpParent->AddConnector( this );
}
Connector::~Connector()
{
if ( mpStartWin )
mpStartWin->RemoveConnector( this );
if ( mpEndWin )
mpEndWin->RemoveConnector( this );
if ( mpParent )
mpParent->RemoveConnector( this );
mpParent->Invalidate( Rectangle( mStart, mEnd ));
mpParent->Invalidate( Rectangle( mEnd - Point( 3, 3), mEnd + Point( 3, 3)));
}
2006-04-20 09:16:35 -05:00
void Connector::Initialize( ObjectWin* pStartWin, ObjectWin* pEndWin, BOOL bVis )
2004-02-26 07:51:54 -06:00
{
mpStartWin = pStartWin;
mpEndWin = pEndWin;
mpStartWin->AddConnector( this );
mpEndWin->AddConnector( this );
mCenter = GetMiddle();
mStart = pStartWin->GetFixPoint( mCenter );
mEnd = pEndWin->GetFixPoint( mCenter );
mnStartId = pStartWin->GetId();
mnEndId = pEndWin->GetId();
2006-04-20 09:16:35 -05:00
bVisible = bVis;
2004-02-26 07:51:54 -06:00
2006-04-20 09:16:35 -05:00
// if ( mpParent->IsPaintEnabled())
if ( IsVisible() )
2004-02-26 07:51:54 -06:00
{
mpParent->DrawLine( mEnd, mStart );
mpParent->DrawEllipse( Rectangle( mEnd - Point( 2, 2), mEnd + Point( 2, 2)));
}
2006-04-20 09:16:35 -05:00
UpdateVisibility(); //null_Project
2004-02-26 07:51:54 -06:00
}
void Connector::UpdateVisibility()
{
bVisible = mpStartWin->IsVisible() && mpEndWin->IsVisible();
}
Point Connector::GetMiddle()
{
Point aStartPoint = mpStartWin->GetPosPixel();
Size aStartSize = mpStartWin->GetSizePixel();
int nMoveHorz, nMoveVert;
aStartPoint.Move( aStartSize.Width() / 2, aStartSize.Height() / 2 );
Point aEndPoint = mpEndWin->GetPosPixel();
Size aEndSize = mpEndWin->GetSizePixel();
aEndPoint.Move( aEndSize.Width() / 2, aEndSize.Height() / 2 );
Point aRetPoint = aEndPoint;
nMoveHorz = aStartPoint.X() - aEndPoint.X();
if ( nMoveHorz )
nMoveHorz /= 2;
nMoveVert = aStartPoint.Y() - aEndPoint.Y();
if ( nMoveVert )
nMoveVert /= 2;
aRetPoint.Move( nMoveHorz, nMoveVert );
return aRetPoint;
}
void Connector::Paint( const Rectangle& rRect )
{
2006-04-20 09:16:35 -05:00
//MyApp *pApp = (MyApp*)GetpApp();
//SolDep *pSoldep = pApp->GetSolDep();
if (msbHideMode)
{
/*
if ((mpStartWin->GetMarkMode() == 0) || (mpEndWin->GetMarkMode() == 0))
{
//bVisible = FALSE;
UpdateVisibility();
fprintf( ((MyApp*)GetpApp())->pDebugFile, "FALSE connctr: Start: %s %i - End: %s %i\n",
mpStartWin->GetBodyText().GetBuffer(),mpStartWin->GetMarkMode(),
mpEndWin->GetBodyText().GetBuffer(),mpEndWin->GetMarkMode());
} else
{
bVisible = TRUE;
fprintf( ((MyApp*)GetpApp())->pDebugFile, "TRUE connctr: Start: %s %i - End: %s %i\n",
mpStartWin->GetBodyText().GetBuffer(),mpStartWin->GetMarkMode(),
mpEndWin->GetBodyText().GetBuffer(),mpEndWin->GetMarkMode());
}
*/
if (!(mpStartWin->IsNullObject())) //null_project
{
if (mpStartWin->GetMarkMode() == 0)
{
mpStartWin->SetViewMask(0); //objwin invisible
} else
{
mpStartWin->SetViewMask(1); //objwin visible
}
}
if (!(mpEndWin->IsNullObject()))
{
if (mpEndWin->GetMarkMode() == 0)
{
mpEndWin->SetViewMask(0); //objwin invisible
} else
{
mpEndWin->SetViewMask(1); //objwin visible
}
}
UpdateVisibility();
} else //IsHideMode
{
//bVisible = TRUE;
if (!(mpStartWin->IsNullObject())) //null_project
{
mpStartWin->SetViewMask(1);
}
if (!(mpEndWin->IsNullObject())) //null_project
{
mpEndWin->SetViewMask(1);
}
UpdateVisibility();
}
if ( (mpStartWin->GetBodyText() != ByteString("null")) && //null_project
(mpEndWin->GetBodyText() != ByteString("null")) && IsVisible()) //null_project
{
2004-02-26 07:51:54 -06:00
mpParent->DrawLine( mEnd, mStart );
mpParent->DrawEllipse( Rectangle( mEnd - Point( 2, 2), mEnd + Point( 2, 2)));
}
}
void Connector::UpdatePosition( ObjectWin* pWin, BOOL bPaint )
{
// more than one call ?
//
Point OldStart, OldEnd;
2006-04-20 09:16:35 -05:00
static ULONG nCallCount = 0;
2004-02-26 07:51:54 -06:00
2006-04-20 09:16:35 -05:00
//MyApp *pApp = (MyApp*)GetpApp();
//SolDep *pSoldep = pApp->GetSolDep();
if (msbHideMode)
bVisible = 1;
if ( nCallCount ) // only one call
2004-02-26 07:51:54 -06:00
nCallCount++;
else
{
nCallCount++;
while ( nCallCount )
{
if ( bPaint )
{
OldStart = mStart;
OldEnd = mEnd;
}
mCenter = GetMiddle();
mStart=mpStartWin->GetFixPoint( mCenter, bPaint );
mEnd=mpEndWin->GetFixPoint( mCenter, bPaint );
if ( bPaint )
{
mpParent->Invalidate( Rectangle( OldStart, OldEnd ));
mpParent->Invalidate( Rectangle( OldEnd - Point( 2, 2), OldEnd + Point( 2, 2)));
2006-04-20 09:16:35 -05:00
//Don't paint "null_project" connectors
if ( (mpStartWin->GetBodyText() != ByteString("null")) && //null_project
(mpEndWin->GetBodyText() != ByteString("null"))) //null_project
{
Paint ( Rectangle( mEnd - Point( 3, 3), mEnd + Point( 3, 3)));
Paint ( Rectangle( mEnd, mStart ));
}
2004-02-26 07:51:54 -06:00
}
nCallCount--;
}
}
}
USHORT Connector::Save( SvFileStream& rOutFile )
{
rOutFile << mpStartWin->GetId();
rOutFile << mpEndWin->GetId();
return 0;
}
USHORT Connector::Load( SvFileStream& rInFile )
{
rInFile >> mnStartId;
rInFile >> mnEndId;
return 0;
}
ObjectWin* Connector::GetOtherWin( ObjectWin* pWin )
{
2006-04-20 09:16:35 -05:00
// get correspondent object ptr
2004-02-26 07:51:54 -06:00
if ( mpStartWin == pWin )
return mpEndWin;
else
if ( mpEndWin == pWin )
return mpStartWin;
return NULL;
}
ULONG Connector::GetOtherId( ULONG nId )
{
2006-04-20 09:16:35 -05:00
// get correspondent object id
2004-02-26 07:51:54 -06:00
if ( mnStartId == nId )
return mnEndId;
else
if ( mnEndId == nId )
return mnStartId;
return NULL;
}
ULONG Connector::GetLen()
{
double dx, dy;
dx = mStart.X() - mEnd.X();
dy = mStart.Y() - mEnd.Y();
return (ULONG) sqrt( dx * dx + dy * dy );
2004-02-26 07:51:54 -06:00
}
BOOL Connector::IsStart( ObjectWin* pWin )
{
return pWin == mpStartWin;
}