1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include <tools/list.hxx>
29 #include <tools/debug.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/help.hxx>
32 #include <vcl/wall.hxx>
34 #include <soldep/objwin.hxx>
35 #include <soldep/depwin.hxx>
36 //#include "depapp.hxx"
37 #include <soldep/depper.hxx>
38 //#include "prjdep.hxx"
39 #include <soldep/connctr.hxx>
42 static Color aDefaultColor
= 0L;
43 static Wallpaper
* pDefaultWallpaper
= 0L;
45 // Initialize static class member
46 BOOL
ObjectWin::msbHideMode
= FALSE
;
47 ULONG
ObjectWin::msnGlobalViewMask
= 0;
50 UINT32 aColorMap
[] = {
51 RGB_COLORDATA( 0xFF, 0xFF, 0x80 ), //MARKMODE_DEFAULT 0
52 COL_GREEN
, //MARKMODE_DEPENDING 1
53 COL_RED
, //MARKMODE_NEEDED 2
55 COL_GRAY
, //MARKMODE_ACTIVATED 4
58 COL_LIGHTMAGENTA
, //1+2+4
59 COL_BLUE
, //MARKMODE_SELECTED 8
62 COL_LIGHTCYAN
, //1+2+8
74 /*****************************************************************************/
75 ObjectWin::ObjectWin( Window
* pParent
, WinBits nWinStyle
)
76 /*****************************************************************************/
77 : Window( pParent
, nWinStyle
),
84 mbMenuExecute( FALSE
),
90 SetBackground( Wallpaper( aColorMap
[0] ));
92 aTipTimer
.SetTimeout( 500 );
93 aTipTimer
.SetTimeoutHdl(
94 LINK( this, ObjectWin
, TipHdl
));
96 SetFont( Font( GetFont() ) );
97 Font
aFont( GetFont() );
98 Size aSize
= aFont
.GetSize();
99 aFont
.SetSize( aSize
);
102 EnableClipSiblings();
103 SetZOrder( NULL
, WINDOW_ZORDER_FIRST
);
104 mpPopup
= new PopupMenu();
105 mpPopup
->InsertItem( OBJWIN_EDIT_TEXT
, String::CreateFromAscii( "Details" ));
106 mpPopup
->InsertItem( OBJWIN_ADD_CONNECTOR
, String::CreateFromAscii( "New connection" ));
107 mpPopup
->InsertItem( OBJWIN_REMOVE_WIN
, String::CreateFromAscii( "Remove object" ));
108 mpPopup
->InsertItem( OBJWIN_VIEW_CONTENT
, String::CreateFromAscii( "View content" ));
109 // mpPopup->InsertSeparator();
110 mpPopup
->SetSelectHdl( LINK( this, ObjectWin
, PopupSelected
));
111 mpPopup
->SetDeactivateHdl( LINK( this, ObjectWin
, PopupDeactivated
));
112 mnPopupStaticItems
= mpPopup
->GetItemCount();
114 if ( ! pDefaultWallpaper
)
116 pDefaultWallpaper
= new Wallpaper( GetBackground() );
117 aDefaultColor
= GetTextColor();
122 /*****************************************************************************/
123 ObjectWin::~ObjectWin()
124 /*****************************************************************************/
126 while ( mConnections
.Count() > 0 )
128 delete mConnections
.GetObject( 0 );
132 void ObjectWin::SetHideMode(BOOL bHide
)
135 mConnections
.GetObject(0)->SetHideMode(msbHideMode
);
138 BOOL
ObjectWin::ToggleHideMode()
140 msbHideMode
= !msbHideMode
;
141 mConnections
.GetObject(0)->SetHideMode(msbHideMode
);
145 /*****************************************************************************/
146 void ObjectWin::SetViewMask( ULONG nMask
)
147 /*****************************************************************************/
151 if ( mnViewMask
& msnGlobalViewMask
) {
159 for ( ULONG i
= 0; i
< mConnections
.Count(); i
++ )
160 mConnections
.GetObject( i
)->UpdateVisibility();
163 /*****************************************************************************/
164 void ObjectWin::SetBodyText( const ByteString
& rNewString
)
165 /*****************************************************************************/
167 msBodyText
= rNewString
;
170 /*****************************************************************************/
171 ByteString
& ObjectWin::GetBodyText()
172 /*****************************************************************************/
177 /*****************************************************************************/
178 void ObjectWin::SetTipText( const ByteString
& rNewString
)
179 /*****************************************************************************/
181 msTipText
= rNewString
;
184 /*****************************************************************************/
185 ByteString
& ObjectWin::GetTipText()
186 /*****************************************************************************/
191 /*****************************************************************************/
192 Point
ObjectWin::GetFixPoint( const Point
& rRefPoint
, BOOL bUseRealPos
)
193 /*****************************************************************************/
197 aLocalPoint
= GetPosPixel();
199 aLocalPoint
= GetCalcPosPixel();
201 Size aLocalSize
= GetSizePixel();
204 USHORT nRefX
= aLocalPoint
.X() + aLocalSize
.Width() / 2 ;
205 USHORT nRefY
= aLocalPoint
.Y() + aLocalSize
.Height() / 2 ;
208 //if ( nRefX < 0 ) nRefX = 0;
209 //if ( nRefY < 0 ) nRefY = 0;
211 if ( rRefPoint
.X() > nRefX
)
213 if ( rRefPoint
.Y() > nRefY
)
215 if ( Abs( rRefPoint
.X() - nRefX
) > Abs( rRefPoint
.Y() - nRefY
))
217 aRetPoint
.X() = aLocalPoint
.X() + aLocalSize
.Width();
218 aRetPoint
.Y() = nRefY
;
222 aRetPoint
.X() = nRefX
;
223 aRetPoint
.Y() = aLocalPoint
.Y() + aLocalSize
.Height();
228 if ( Abs( rRefPoint
.X() - nRefX
) > Abs( rRefPoint
.Y() - nRefY
))
230 aRetPoint
.X() = aLocalPoint
.X() + aLocalSize
.Width();
231 aRetPoint
.Y() = nRefY
;
235 aRetPoint
.X() = nRefX
;
236 aRetPoint
.Y() = aLocalPoint
.Y();
242 if ( rRefPoint
.Y() > nRefY
)
244 if ( Abs( rRefPoint
.X() - nRefX
) > Abs( rRefPoint
.Y() - nRefY
))
246 aRetPoint
.X() = aLocalPoint
.X();
247 aRetPoint
.Y() = nRefY
;
251 aRetPoint
.X() = nRefX
;
252 aRetPoint
.Y() = aLocalPoint
.Y() + aLocalSize
.Height();
257 if ( Abs( rRefPoint
.X() - nRefX
) > Abs( rRefPoint
.Y() - nRefY
))
259 aRetPoint
.X() = aLocalPoint
.X();
260 aRetPoint
.Y() = nRefY
;
264 aRetPoint
.X() = nRefX
;
265 aRetPoint
.Y() = aLocalPoint
.Y();
270 return PixelToLogic(aRetPoint
);
274 /*****************************************************************************/
275 void ObjectWin::AddConnector( Connector
* pNewCon
)
276 /*****************************************************************************/
278 mConnections
.Insert( pNewCon
);
281 /*****************************************************************************/
282 BOOL
ObjectWin::ConnectionExistsInAnyDirection( ObjectWin
*pWin
)
283 /*****************************************************************************/
285 for ( ULONG i
= 0; i
< mConnections
.Count(); i
++ )
286 if ( mConnections
.GetObject( i
)->GetOtherWin( this ) == pWin
)
292 /*****************************************************************************/
293 void ObjectWin::RemoveConnector( Connector
* pOldCon
)
294 /*****************************************************************************/
296 mConnections
.Remove( pOldCon
);
299 /*****************************************************************************/
300 Connector
* ObjectWin::GetConnector( ULONG nIndex
)
301 /*****************************************************************************/
303 ULONG nConCount
= mConnections
.Count();
305 if ( nIndex
< nConCount
)
306 return mConnections
.GetObject( nIndex
);
310 /*****************************************************************************/
311 Connector
* ObjectWin::GetConnector( ULONG nStartId
, ULONG nEndId
)
312 /*****************************************************************************/
314 if ( mnObjectId
!= nStartId
)
319 ULONG nConCount
= mConnections
.Count();
321 for ( i
= 0; i
< nConCount
; i
++ )
323 pCon
= mConnections
.GetObject( i
);
324 if ( pCon
->GetOtherWin( this )->GetId() == nEndId
)
330 void ObjectWin::SetAllConnectorsUnvisible()
333 ULONG nConCount
= mConnections
.Count();
334 for ( ULONG i
= 0; i
< nConCount
; i
++ )
336 pCon
= mConnections
.GetObject( i
);
337 if (pCon
) pCon
->SetVisibility( FALSE
);
341 /*****************************************************************************/
342 void ObjectWin::SetMarkMode( ULONG nMarkMode
)
343 /*****************************************************************************/
345 //Wallpaper aWallpaper;
347 if ( nMarkMode
== MARKMODE_DEFAULT
)
349 if ( pDefaultWallpaper
)
351 maObjWallpaper
= GetBackground();
352 maObjWallpaper
.SetColor( pDefaultWallpaper
->GetColor() );
353 SetBackground( maObjWallpaper
);
354 SetTextColor( aDefaultColor
);
359 mnMarkMode
|= nMarkMode
;
360 maObjWallpaper
= GetBackground();
361 maObjWallpaper
.SetColor( aColorMap
[ mnMarkMode
] );
362 SetBackground( maObjWallpaper
);
363 SetTextColor( COL_WHITE
);
369 /*****************************************************************************/
370 void ObjectWin::UnsetMarkMode( ULONG nMarkMode
)
371 /*****************************************************************************/
373 //Wallpaper aWallpaper;
375 ULONG nOldMode
= mnMarkMode
;
376 mnMarkMode
&= ( !nMarkMode
);
378 if ( nOldMode
!= mnMarkMode
) {
379 if ( mnMarkMode
== MARKMODE_DEFAULT
)
381 if ( pDefaultWallpaper
)
383 maObjWallpaper
= GetBackground();
384 maObjWallpaper
.SetColor( pDefaultWallpaper
->GetColor() );
385 SetBackground( maObjWallpaper
);
386 SetTextColor( aDefaultColor
);
391 maObjWallpaper
= GetBackground();
392 maObjWallpaper
.SetColor( aColorMap
[ mnMarkMode
] ); //mnMarkMode
393 SetBackground( maObjWallpaper
);
394 SetTextColor( COL_WHITE
);
400 /*****************************************************************************/
401 void ObjectWin::MarkNeeded( BOOL bReset
)
402 /*****************************************************************************/
407 ULONG nConCount
= mConnections
.Count();
410 for ( i
= 0; i
< nConCount
; i
++ )
412 pCon
= mConnections
.GetObject( i
);
413 if ( pCon
&& !pCon
->IsStart( this))
415 pWin
= pCon
->GetOtherWin( this );
419 pWin
->UnsetMarkMode( MARKMODE_NEEDED
);
421 pWin
->SetMarkMode( MARKMODE_NEEDED
);
422 pWin
->MarkNeeded( bReset
); // recursive call
428 /*****************************************************************************/
429 void ObjectWin::MarkDepending( BOOL bReset
)
430 /*****************************************************************************/
438 ULONG nConCount
= mConnections
.Count();
441 for ( i
= 0; i
< nConCount
; i
++ )
443 pCon
= mConnections
.GetObject( i
);
444 if ( pCon
&& pCon
->IsStart( this) )
446 pWin
= pCon
->GetOtherWin( this );
450 pWin
->UnsetMarkMode( MARKMODE_DEPENDING
);
452 pWin
->SetMarkMode( MARKMODE_DEPENDING
);
453 pWin
->MarkDepending( bReset
); // recursive call
459 /*****************************************************************************/
460 void ObjectWin::Paint( const Rectangle
& rRect
)
461 /*****************************************************************************/
463 Size aWinSize
= PixelToLogic( GetOutputSizePixel() );
465 ByteString sbt
= msBodyText
; //debug
466 //sbt += " "; //debug
467 //sbt += ByteString::CreateFromInt32(mnMarkMode); //debug
468 aTextSize
.Width() = GetTextWidth( String( msBodyText
, RTL_TEXTENCODING_UTF8
));
469 aTextSize
.Height() = GetTextHeight();
470 Point
aPos( aWinSize
.Width() / 2 - aTextSize
.Width() / 2,
471 aWinSize
.Height() / 2 - aTextSize
.Height() / 2 );
473 //DrawText( aPos , String( sBodyText, RTL_TEXTENCODING_UTF8 ));
474 if (msBodyText
=="null") //don't paint this "window"
479 DrawText( aPos
, String( sbt
, RTL_TEXTENCODING_UTF8
)); //debug
482 void ObjectWin::DrawOutput( OutputDevice
* pDevice
, const Point
& rOffset
)
483 /*****************************************************************************/
485 Size aWinSize
= PixelToLogic( GetSizePixel() );
487 ByteString sbt
= msBodyText
;
488 aTextSize
.Width() = GetTextWidth( String( msBodyText
, RTL_TEXTENCODING_UTF8
));
489 aTextSize
.Height() = GetTextHeight();
490 Point aPos
= GetPosPixel();
491 Point
aTextPos( aWinSize
.Width() / 2 - aTextSize
.Width() / 2,
492 aWinSize
.Height() / 2 - aTextSize
.Height() / 2 );
494 aPos
= pDevice
->PixelToLogic( aPos
) - rOffset
;
495 aTextPos
= pDevice
->PixelToLogic( aTextPos
) - rOffset
;
496 if ( msBodyText
!="null" )
498 pDevice
->SetFillColor( GetBackground().GetColor() );
499 pDevice
->DrawRect( Rectangle( aPos
, pDevice
->PixelToLogic( GetSizePixel() ) ) );
500 Font
aFont( GetFont() );
501 Size aSize
= aFont
.GetSize();
502 aSize
= pDevice
->PixelToLogic( aSize
);
503 aFont
.SetSize( aSize
);
504 pDevice
->SetFont( aFont
);
505 pDevice
->SetTextColor( GetTextColor() );
506 pDevice
->DrawText( aTextPos
, String( sbt
, RTL_TEXTENCODING_UTF8
) );
510 /*****************************************************************************/
511 void ObjectWin::MouseButtonDown( const MouseEvent
& rMEvt
)
512 /*****************************************************************************/
514 //Notify Soldep to clear ObjectList
515 SetZOrder( NULL
, WINDOW_ZORDER_FIRST
);
518 // workaround fuer vcl-bug
519 // GetWindow( WINDOW_REALPARENT)->Invalidate();
520 // MyApp *pApp = (MyApp*)GetpApp();
521 // SolDep *pSoldep = pApp->GetSolDep();
523 maMouseOffset
= rMEvt
.GetPosPixel();
524 if ( rMEvt
.IsLeft() )
527 if ( rMEvt
.IsMod2() ) // alt + mouse click left
529 CallEventListeners( VCLEVENT_USER_MOUSEBUTTON_DOWN_ALT
, this );
532 CallEventListeners( VCLEVENT_USER_MOUSEBUTTON_DOWN
, this );
534 if( rMEvt
.GetClicks() == 2 )
535 CallEventListeners( VCLEVENT_USER_MOUSEBUTTON_DOWN_DBLCLICK
, this );
536 else if ( !rMEvt
.IsShift() && !((DepWin
*)GetParent())->IsStartNewCon())
538 //((DepWin*)GetParent())->SaveSelectedObjWin(&this);
544 /*****************************************************************************/
545 void ObjectWin::MouseButtonUp( const MouseEvent
& rMEvt
)
546 /*****************************************************************************/
548 fprintf(stdout
,"ObjectWin::MouseButtonUp\n");
549 if ( rMEvt
.IsLeft() )
551 if ( rMEvt
.IsShift() || ((DepWin
*)GetParent())->IsStartNewCon())
552 CallEventListeners( VCLEVENT_USER_MOUSEBUTTON_UP_SHFT
, this );
553 // ((DepWin*)GetParent())->NewConnector( this );
556 CallEventListeners( VCLEVENT_USER_MOUSEBUTTON_UP
, this );
557 if ( IsMouseCaptured() ) ReleaseMouse();
560 else if ( rMEvt
.IsRight() )
564 while ( mnPopupStaticItems
< mpPopup
->GetItemCount() )
566 mpPopup
->RemoveItem( mnPopupStaticItems
);
569 if ( mConnections
.Count()) {
570 mpPopup
->InsertSeparator();
572 for( i
= 0; i
< mConnections
.Count() ; i
++ )
574 mpPopup
->InsertItem( mnPopupStaticItems
+ i
+ 1, String( ((mConnections
.GetObject( i
))->GetOtherWin( this ))->GetBodyText(), RTL_TEXTENCODING_UTF8
));
577 mbMenuExecute
= TRUE
;
578 mpPopup
->Execute( GetParent(), rMEvt
.GetPosPixel() + GetPosPixel());
582 /*****************************************************************************/
583 void ObjectWin::MouseMove( const MouseEvent
& rMEvt
)
584 /*****************************************************************************/
586 if ( IsMouseCaptured() )
590 Point
aNewWinPos( GetPosPixel() + rMEvt
.GetPosPixel() - maMouseOffset
);
592 aNewWinPos
.X() = Max( 0L, aNewWinPos
.X());
593 aNewWinPos
.Y() = Max( 0L, aNewWinPos
.Y());
594 SetPosPixel( aNewWinPos
);
595 //int t = mConnections.Count();
597 for ( i
=0; i
< mConnections
.Count();i
++)
599 mConnections
.GetObject( i
)->UpdatePosition( this );
602 else // !IsMouseCaptured()
604 if ( rMEvt
.IsLeaveWindow() )
609 MouseEvent
aNewMEvt( rMEvt
.GetPosPixel() + GetPosPixel());
611 GetParent()->MouseMove( aNewMEvt
); //call to DepWin::MouseMove
615 /*****************************************************************************/
616 USHORT
ObjectWin::Save( SvFileStream
& rOutFile
)
617 /*****************************************************************************/
622 /*****************************************************************************/
623 USHORT
ObjectWin::Load( SvFileStream
& rInFile
)
624 /*****************************************************************************/
629 /*****************************************************************************/
630 void ObjectWin::SetId( ULONG nId
)
631 /*****************************************************************************/
636 /*****************************************************************************/
637 ULONG
ObjectWin::GetId()
638 /*****************************************************************************/
643 /*****************************************************************************/
644 void ObjectWin::UpdateConnectors()
645 /*****************************************************************************/
649 for ( i
= 0; i
< mConnections
.Count(); i
++ )
651 mConnections
.GetObject( i
)->UpdatePosition( this );
655 IMPL_LINK( ObjectWin
, PopupSelected
, PopupMenu
*, mpPopup_l
)
657 USHORT nItemId
= mpPopup_l
->GetCurItemId();
661 case OBJWIN_EDIT_TEXT
:
662 DBG_ASSERT( FALSE
,"edit");
664 case OBJWIN_REMOVE_WIN
:
665 // DBG_ASSERT( FALSE,"remove");
666 // DBG_ASSERT( mpDepperDontuseme,"remove");
667 //mpDepperDontuseme->RemoveObject(mpDepperDontuseme->mpObjectList, ( USHORT ) GetId());
669 case OBJWIN_ADD_CONNECTOR
:
670 // DBG_ASSERT( FALSE,"add con");
671 ((DepWin
*)GetParent())->NewConnector( this );
673 case OBJWIN_VIEW_CONTENT
:
674 // DBG_ASSERT( FALSE,"view cnt");
675 // mpDepperDontuseme->ViewContent( msBodyText );
676 // TBD: CallEventListener
679 // DBG_ASSERT( FALSE, String (nItemId) );
680 Connector
* pCon
= mConnections
.GetObject( nItemId
- mnPopupStaticItems
- 1);
683 // mpDepperDontuseme->RemoveConnector( pCon->GetStartId(), pCon->GetEndId());
684 // TBD: CallEventListener
691 /*****************************************************************************/
692 IMPL_LINK( ObjectWin
, TipHdl
, void *, EMTY_ARG
)
693 /*****************************************************************************/
697 if ( msTipText
.Len()) {
698 Point
aPos( GetpApp()->GetAppWindow()->GetPointerPosPixel());
699 Help::ShowBalloon( GetpApp()->GetAppWindow(),
700 Point( aPos
.X(), aPos
.Y()),
701 String( msTipText
, RTL_TEXTENCODING_UTF8
));
706 /*****************************************************************************/
707 //void ObjectWin::GetFocus()
708 /*****************************************************************************/
710 //SetMarkMode( MARKMODE_SELECTED );
713 /*****************************************************************************/
714 void ObjectWin::LoseFocus()
715 /*****************************************************************************/
717 if ( !mbMenuExecute
&& !msbHideMode
) {
718 UnsetMarkMode( MARKMODE_SELECTED
);
719 UnsetMarkMode( MARKMODE_ACTIVATED
);
721 MarkDepending( TRUE
);
724 mbMenuExecute
= FALSE
;
727 /*****************************************************************************/
728 IMPL_LINK( ObjectWin
, PopupDeactivated
, PopupMenu
*, mpPopup_l
)
729 /*****************************************************************************/
731 mbMenuExecute
= FALSE
;
734 UnsetMarkMode( MARKMODE_SELECTED
);
735 UnsetMarkMode( MARKMODE_ACTIVATED
);
737 MarkDepending( TRUE
);
743 /*****************************************************************************/
744 void ObjectWin::Command( const CommandEvent
& rEvent
)
745 /*****************************************************************************/
747 fprintf(stdout
, "ObjectWin::Command");
748 // mpDepperDontuseme->GetGraphWin()->Command( rEvent );
749 // TBD: CallEventListener
753 /*****************************************************************************/
754 /*****************************************************************************/
756 ObjectList::ObjectList() : ObjWinList()
760 /*****************************************************************************/
761 void ObjectList::ResetSelectedObject()
762 /*****************************************************************************/
766 ULONG nCount_l
= Count();
767 ObjectWin
* pObjectWin
= NULL
;
768 for (ULONG i
=0; i
< nCount_l
; i
++ )
770 pObjectWin
= GetObject( i
);
771 pObjectWin
->UnsetMarkMode( MARKMODE_SELECTED
);
772 pObjectWin
->UnsetMarkMode( MARKMODE_NEEDED
);
773 pObjectWin
->UnsetMarkMode( MARKMODE_DEPENDING
);
774 pObjectWin
->SetActualWallpaper(*pDefaultWallpaper
);
775 pObjectWin
->SetAllConnectorsUnvisible();
780 /*****************************************************************************/
781 ObjectWin
* ObjectList::GetPtrByName( const ByteString
& rText
)
782 /*****************************************************************************/
785 ULONG nCount_l
= Count();
786 ObjectWin
* pObjectWin
= NULL
;
787 while ( i
< nCount_l
)
789 pObjectWin
= GetObject( i
);
790 ByteString sPrj
= pObjectWin
->GetBodyText();
791 if (sPrj
== rText
) return pObjectWin
;
797 ObjectList
* ObjectList::FindTopLevelModules()
799 ObjectList
* pList
= new ObjectList
;
800 for ( USHORT i
=0; i
<Count(); i
++ )
802 ObjectWin
* pObjectWin
= GetObject( i
);
803 if ( pObjectWin
->IsTop() )
804 pList
->Insert( pObjectWin
);
810 BOOL
ObjectWin::IsTop()
812 ULONG nConCount
= mConnections
.Count();
813 for ( ULONG i
= 0; i
< nConCount
; i
++ )
815 Connector
* pCon
= mConnections
.GetObject( i
);
816 if ( pCon
&& pCon
->IsStart( this) )