1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objwin.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <tools/list.hxx>
32 #include <tools/debug.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/help.hxx>
35 #include <vcl/wall.hxx>
37 #include <soldep/objwin.hxx>
38 #include <soldep/depwin.hxx>
39 //#include "depapp.hxx"
40 #include <soldep/depper.hxx>
41 //#include "prjdep.hxx"
42 #include <soldep/connctr.hxx>
45 static Color aDefaultColor
= 0L;
46 static Wallpaper
* pDefaultWallpaper
= 0L;
48 // Initialize static class member
49 BOOL
ObjectWin::msbHideMode
= FALSE
;
50 ULONG
ObjectWin::msnGlobalViewMask
= 0;
53 UINT32 aColorMap
[] = {
54 COL_TRANSPARENT
, //MARKMODE_DEFAULT 0
55 COL_GREEN
, //MARKMODE_DEPENDING 1
56 COL_RED
, //MARKMODE_NEEDED 2
58 COL_YELLOW
, //MARKMODE_ACTIVATED 4
61 COL_LIGHTMAGENTA
, //1+2+4
62 COL_BLUE
, //MARKMODE_SELECTED 8
65 COL_LIGHTCYAN
, //1+2+8
77 /*****************************************************************************/
78 ObjectWin::ObjectWin( Window
* pParent
, WinBits nWinStyle
)
79 /*****************************************************************************/
80 : Window( pParent
, nWinStyle
),
87 mbMenuExecute( FALSE
),
93 SetBackground( Wallpaper( Color( COL_WHITE
)));
95 aTipTimer
.SetTimeout( 500 );
96 aTipTimer
.SetTimeoutHdl(
97 LINK( this, ObjectWin
, TipHdl
));
99 SetFont( Font( GetFont() ) );
100 Font
aFont( GetFont() );
101 Size aSize
= aFont
.GetSize();
102 aFont
.SetSize( aSize
);
105 EnableClipSiblings();
106 SetZOrder( NULL
, WINDOW_ZORDER_FIRST
);
107 mpPopup
= new PopupMenu();
108 mpPopup
->InsertItem( OBJWIN_EDIT_TEXT
, String::CreateFromAscii( "Details" ));
109 mpPopup
->InsertItem( OBJWIN_ADD_CONNECTOR
, String::CreateFromAscii( "New connection" ));
110 mpPopup
->InsertItem( OBJWIN_REMOVE_WIN
, String::CreateFromAscii( "Remove object" ));
111 mpPopup
->InsertItem( OBJWIN_VIEW_CONTENT
, String::CreateFromAscii( "View content" ));
112 // mpPopup->InsertSeparator();
113 mpPopup
->SetSelectHdl( LINK( this, ObjectWin
, PopupSelected
));
114 mpPopup
->SetDeactivateHdl( LINK( this, ObjectWin
, PopupDeactivated
));
115 mnPopupStaticItems
= mpPopup
->GetItemCount();
117 if ( ! pDefaultWallpaper
)
119 pDefaultWallpaper
= new Wallpaper( GetBackground() );
120 aDefaultColor
= GetTextColor();
125 /*****************************************************************************/
126 ObjectWin::~ObjectWin()
127 /*****************************************************************************/
129 while ( mConnections
.Count() > 0 )
131 delete mConnections
.GetObject( 0 );
135 void ObjectWin::SetHideMode(BOOL bHide
)
138 mConnections
.GetObject(0)->SetHideMode(msbHideMode
);
141 BOOL
ObjectWin::ToggleHideMode()
143 msbHideMode
= !msbHideMode
;
144 mConnections
.GetObject(0)->SetHideMode(msbHideMode
);
148 /*****************************************************************************/
149 void ObjectWin::SetViewMask( ULONG nMask
)
150 /*****************************************************************************/
154 if ( mnViewMask
& msnGlobalViewMask
) {
162 for ( ULONG i
= 0; i
< mConnections
.Count(); i
++ )
163 mConnections
.GetObject( i
)->UpdateVisibility();
166 /*****************************************************************************/
167 void ObjectWin::SetBodyText( const ByteString
& rNewString
)
168 /*****************************************************************************/
170 msBodyText
= rNewString
;
173 /*****************************************************************************/
174 ByteString
& ObjectWin::GetBodyText()
175 /*****************************************************************************/
180 /*****************************************************************************/
181 void ObjectWin::SetTipText( const ByteString
& rNewString
)
182 /*****************************************************************************/
184 msTipText
= rNewString
;
187 /*****************************************************************************/
188 ByteString
& ObjectWin::GetTipText()
189 /*****************************************************************************/
194 /*****************************************************************************/
195 Point
ObjectWin::GetFixPoint( const Point
& rRefPoint
, BOOL bUseRealPos
)
196 /*****************************************************************************/
200 aLocalPoint
= GetPosPixel();
202 aLocalPoint
= GetCalcPosPixel();
204 Size aLocalSize
= GetSizePixel();
207 USHORT nRefX
= aLocalPoint
.X() + aLocalSize
.Width() / 2 ;
208 USHORT nRefY
= aLocalPoint
.Y() + aLocalSize
.Height() / 2 ;
211 //if ( nRefX < 0 ) nRefX = 0;
212 //if ( nRefY < 0 ) nRefY = 0;
214 if ( rRefPoint
.X() > nRefX
)
216 if ( rRefPoint
.Y() > nRefY
)
218 if ( Abs( rRefPoint
.X() - nRefX
) > Abs( rRefPoint
.Y() - nRefY
))
220 aRetPoint
.X() = aLocalPoint
.X() + aLocalSize
.Width();
221 aRetPoint
.Y() = nRefY
;
225 aRetPoint
.X() = nRefX
;
226 aRetPoint
.Y() = aLocalPoint
.Y() + aLocalSize
.Height();
231 if ( Abs( rRefPoint
.X() - nRefX
) > Abs( rRefPoint
.Y() - nRefY
))
233 aRetPoint
.X() = aLocalPoint
.X() + aLocalSize
.Width();
234 aRetPoint
.Y() = nRefY
;
238 aRetPoint
.X() = nRefX
;
239 aRetPoint
.Y() = aLocalPoint
.Y();
245 if ( rRefPoint
.Y() > nRefY
)
247 if ( Abs( rRefPoint
.X() - nRefX
) > Abs( rRefPoint
.Y() - nRefY
))
249 aRetPoint
.X() = aLocalPoint
.X();
250 aRetPoint
.Y() = nRefY
;
254 aRetPoint
.X() = nRefX
;
255 aRetPoint
.Y() = aLocalPoint
.Y() + aLocalSize
.Height();
260 if ( Abs( rRefPoint
.X() - nRefX
) > Abs( rRefPoint
.Y() - nRefY
))
262 aRetPoint
.X() = aLocalPoint
.X();
263 aRetPoint
.Y() = nRefY
;
267 aRetPoint
.X() = nRefX
;
268 aRetPoint
.Y() = aLocalPoint
.Y();
273 return PixelToLogic(aRetPoint
);
277 /*****************************************************************************/
278 void ObjectWin::AddConnector( Connector
* pNewCon
)
279 /*****************************************************************************/
281 mConnections
.Insert( pNewCon
);
284 /*****************************************************************************/
285 BOOL
ObjectWin::ConnectionExistsInAnyDirection( ObjectWin
*pWin
)
286 /*****************************************************************************/
288 for ( ULONG i
= 0; i
< mConnections
.Count(); i
++ )
289 if ( mConnections
.GetObject( i
)->GetOtherWin( this ) == pWin
)
295 /*****************************************************************************/
296 void ObjectWin::RemoveConnector( Connector
* pOldCon
)
297 /*****************************************************************************/
299 mConnections
.Remove( pOldCon
);
302 /*****************************************************************************/
303 Connector
* ObjectWin::GetConnector( ULONG nIndex
)
304 /*****************************************************************************/
306 ULONG nConCount
= mConnections
.Count();
308 if ( nIndex
< nConCount
)
309 return mConnections
.GetObject( nIndex
);
313 /*****************************************************************************/
314 Connector
* ObjectWin::GetConnector( ULONG nStartId
, ULONG nEndId
)
315 /*****************************************************************************/
317 if ( mnObjectId
!= nStartId
)
322 ULONG nConCount
= mConnections
.Count();
324 for ( i
= 0; i
< nConCount
; i
++ )
326 pCon
= mConnections
.GetObject( i
);
327 if ( pCon
->GetOtherWin( this )->GetId() == nEndId
)
333 void ObjectWin::SetAllConnectorsUnvisible()
336 ULONG nConCount
= mConnections
.Count();
337 for ( ULONG i
= 0; i
< nConCount
; i
++ )
339 pCon
= mConnections
.GetObject( i
);
340 if (pCon
) pCon
->SetVisibility( FALSE
);
344 /*****************************************************************************/
345 void ObjectWin::SetMarkMode( ULONG nMarkMode
)
346 /*****************************************************************************/
348 //Wallpaper aWallpaper;
350 if ( nMarkMode
== MARKMODE_DEFAULT
)
352 if ( pDefaultWallpaper
)
354 maObjWallpaper
= GetBackground();
355 maObjWallpaper
.SetColor( pDefaultWallpaper
->GetColor() );
356 SetBackground( maObjWallpaper
);
357 SetTextColor( aDefaultColor
);
362 mnMarkMode
|= nMarkMode
;
363 maObjWallpaper
= GetBackground();
364 maObjWallpaper
.SetColor( aColorMap
[ mnMarkMode
] );
365 SetBackground( maObjWallpaper
);
366 SetTextColor( COL_WHITE
);
372 /*****************************************************************************/
373 void ObjectWin::UnsetMarkMode( ULONG nMarkMode
)
374 /*****************************************************************************/
376 //Wallpaper aWallpaper;
378 ULONG nOldMode
= mnMarkMode
;
379 mnMarkMode
&= ( !nMarkMode
);
381 if ( nOldMode
!= mnMarkMode
) {
382 if ( mnMarkMode
== MARKMODE_DEFAULT
)
384 if ( pDefaultWallpaper
)
386 maObjWallpaper
= GetBackground();
387 maObjWallpaper
.SetColor( pDefaultWallpaper
->GetColor() );
388 SetBackground( maObjWallpaper
);
389 SetTextColor( aDefaultColor
);
394 maObjWallpaper
= GetBackground();
395 maObjWallpaper
.SetColor( aColorMap
[ mnMarkMode
] ); //mnMarkMode
396 SetBackground( maObjWallpaper
);
397 SetTextColor( COL_WHITE
);
403 /*****************************************************************************/
404 void ObjectWin::MarkNeeded( BOOL bReset
)
405 /*****************************************************************************/
410 ULONG nConCount
= mConnections
.Count();
413 for ( i
= 0; i
< nConCount
; i
++ )
415 pCon
= mConnections
.GetObject( i
);
416 if ( pCon
&& !pCon
->IsStart( this))
418 pWin
= pCon
->GetOtherWin( this );
422 pWin
->UnsetMarkMode( MARKMODE_NEEDED
);
424 pWin
->SetMarkMode( MARKMODE_NEEDED
);
425 pWin
->MarkNeeded( bReset
); // recursive call
431 /*****************************************************************************/
432 void ObjectWin::MarkDepending( BOOL bReset
)
433 /*****************************************************************************/
441 ULONG nConCount
= mConnections
.Count();
444 for ( i
= 0; i
< nConCount
; i
++ )
446 pCon
= mConnections
.GetObject( i
);
447 if ( pCon
&& pCon
->IsStart( this) )
449 pWin
= pCon
->GetOtherWin( this );
453 pWin
->UnsetMarkMode( MARKMODE_DEPENDING
);
455 pWin
->SetMarkMode( MARKMODE_DEPENDING
);
456 pWin
->MarkDepending( bReset
); // recursive call
462 /*****************************************************************************/
463 void ObjectWin::Paint( const Rectangle
& rRect
)
464 /*****************************************************************************/
466 Size aWinSize
= PixelToLogic( GetOutputSizePixel() );
468 ByteString sbt
= msBodyText
; //debug
469 //sbt += " "; //debug
470 //sbt += ByteString::CreateFromInt32(mnMarkMode); //debug
471 aTextSize
.Width() = GetTextWidth( String( msBodyText
, RTL_TEXTENCODING_UTF8
));
472 aTextSize
.Height() = GetTextHeight();
473 Point
aPos( aWinSize
.Width() / 2 - aTextSize
.Width() / 2,
474 aWinSize
.Height() / 2 - aTextSize
.Height() / 2 );
476 //DrawText( aPos , String( sBodyText, RTL_TEXTENCODING_UTF8 ));
477 if (msBodyText
=="null") //don't paint this "window"
482 DrawText( aPos
, String( sbt
, RTL_TEXTENCODING_UTF8
)); //debug
485 void ObjectWin::DrawOutput( OutputDevice
* pDevice
, const Point
& rOffset
)
486 /*****************************************************************************/
488 Size aWinSize
= PixelToLogic( GetSizePixel() );
490 ByteString sbt
= msBodyText
;
491 aTextSize
.Width() = GetTextWidth( String( msBodyText
, RTL_TEXTENCODING_UTF8
));
492 aTextSize
.Height() = GetTextHeight();
493 Point aPos
= GetPosPixel();
494 Point
aTextPos( aWinSize
.Width() / 2 - aTextSize
.Width() / 2,
495 aWinSize
.Height() / 2 - aTextSize
.Height() / 2 );
497 aPos
= pDevice
->PixelToLogic( aPos
) - rOffset
;
498 aTextPos
= pDevice
->PixelToLogic( aTextPos
) - rOffset
;
499 if ( msBodyText
!="null" )
501 pDevice
->SetFillColor( GetBackground().GetColor() );
502 pDevice
->DrawRect( Rectangle( aPos
, pDevice
->PixelToLogic( GetSizePixel() ) ) );
503 Font
aFont( GetFont() );
504 Size aSize
= aFont
.GetSize();
505 aSize
= pDevice
->PixelToLogic( aSize
);
506 aFont
.SetSize( aSize
);
507 pDevice
->SetFont( aFont
);
508 pDevice
->SetTextColor( GetTextColor() );
509 pDevice
->DrawText( aTextPos
, String( sbt
, RTL_TEXTENCODING_UTF8
) );
513 /*****************************************************************************/
514 void ObjectWin::MouseButtonDown( const MouseEvent
& rMEvt
)
515 /*****************************************************************************/
517 //Notify Soldep to clear ObjectList
518 SetZOrder( NULL
, WINDOW_ZORDER_FIRST
);
521 // workaround fuer vcl-bug
522 // GetWindow( WINDOW_REALPARENT)->Invalidate();
523 // MyApp *pApp = (MyApp*)GetpApp();
524 // SolDep *pSoldep = pApp->GetSolDep();
526 maMouseOffset
= rMEvt
.GetPosPixel();
527 if ( rMEvt
.IsLeft() )
530 if ( rMEvt
.IsMod2() ) // alt + mouse click left
532 CallEventListeners( VCLEVENT_USER_MOUSEBUTTON_DOWN_ALT
, this );
535 CallEventListeners( VCLEVENT_USER_MOUSEBUTTON_DOWN
, this );
537 if( rMEvt
.GetClicks() == 2 )
538 CallEventListeners( VCLEVENT_USER_MOUSEBUTTON_DOWN_DBLCLICK
, this );
539 else if ( !rMEvt
.IsShift() && !((DepWin
*)GetParent())->IsStartNewCon())
541 //((DepWin*)GetParent())->SaveSelectedObjWin(&this);
547 /*****************************************************************************/
548 void ObjectWin::MouseButtonUp( const MouseEvent
& rMEvt
)
549 /*****************************************************************************/
551 fprintf(stdout
,"ObjectWin::MouseButtonUp\n");
552 if ( rMEvt
.IsLeft() )
554 if ( rMEvt
.IsShift() || ((DepWin
*)GetParent())->IsStartNewCon())
555 CallEventListeners( VCLEVENT_USER_MOUSEBUTTON_UP_SHFT
, this );
556 // ((DepWin*)GetParent())->NewConnector( this );
559 CallEventListeners( VCLEVENT_USER_MOUSEBUTTON_UP
, this );
560 if ( IsMouseCaptured() ) ReleaseMouse();
563 else if ( rMEvt
.IsRight() )
567 while ( mnPopupStaticItems
< mpPopup
->GetItemCount() )
569 mpPopup
->RemoveItem( mnPopupStaticItems
);
572 if ( mConnections
.Count()) {
573 mpPopup
->InsertSeparator();
575 for( i
= 0; i
< mConnections
.Count() ; i
++ )
577 mpPopup
->InsertItem( mnPopupStaticItems
+ i
+ 1, String( ((mConnections
.GetObject( i
))->GetOtherWin( this ))->GetBodyText(), RTL_TEXTENCODING_UTF8
));
580 mbMenuExecute
= TRUE
;
581 mpPopup
->Execute( GetParent(), rMEvt
.GetPosPixel() + GetPosPixel());
585 /*****************************************************************************/
586 void ObjectWin::MouseMove( const MouseEvent
& rMEvt
)
587 /*****************************************************************************/
589 if ( IsMouseCaptured() )
593 Point
aNewWinPos( GetPosPixel() + rMEvt
.GetPosPixel() - maMouseOffset
);
595 aNewWinPos
.X() = Max( 0L, aNewWinPos
.X());
596 aNewWinPos
.Y() = Max( 0L, aNewWinPos
.Y());
597 SetPosPixel( aNewWinPos
);
598 //int t = mConnections.Count();
600 for ( i
=0; i
< mConnections
.Count();i
++)
602 mConnections
.GetObject( i
)->UpdatePosition( this );
605 else // !IsMouseCaptured()
607 if ( rMEvt
.IsLeaveWindow() )
612 MouseEvent
aNewMEvt( rMEvt
.GetPosPixel() + GetPosPixel());
614 GetParent()->MouseMove( aNewMEvt
); //call to DepWin::MouseMove
618 /*****************************************************************************/
619 USHORT
ObjectWin::Save( SvFileStream
& rOutFile
)
620 /*****************************************************************************/
625 /*****************************************************************************/
626 USHORT
ObjectWin::Load( SvFileStream
& rInFile
)
627 /*****************************************************************************/
632 /*****************************************************************************/
633 void ObjectWin::SetId( ULONG nId
)
634 /*****************************************************************************/
639 /*****************************************************************************/
640 ULONG
ObjectWin::GetId()
641 /*****************************************************************************/
646 /*****************************************************************************/
647 void ObjectWin::UpdateConnectors()
648 /*****************************************************************************/
652 for ( i
= 0; i
< mConnections
.Count(); i
++ )
654 mConnections
.GetObject( i
)->UpdatePosition( this );
658 IMPL_LINK( ObjectWin
, PopupSelected
, PopupMenu
*, mpPopup_l
)
660 USHORT nItemId
= mpPopup_l
->GetCurItemId();
664 case OBJWIN_EDIT_TEXT
:
665 DBG_ASSERT( FALSE
,"edit");
667 case OBJWIN_REMOVE_WIN
:
668 // DBG_ASSERT( FALSE,"remove");
669 // DBG_ASSERT( mpDepperDontuseme,"remove");
670 //mpDepperDontuseme->RemoveObject(mpDepperDontuseme->mpObjectList, ( USHORT ) GetId());
672 case OBJWIN_ADD_CONNECTOR
:
673 // DBG_ASSERT( FALSE,"add con");
674 ((DepWin
*)GetParent())->NewConnector( this );
676 case OBJWIN_VIEW_CONTENT
:
677 // DBG_ASSERT( FALSE,"view cnt");
678 // mpDepperDontuseme->ViewContent( msBodyText );
679 // TBD: CallEventListener
682 // DBG_ASSERT( FALSE, String (nItemId) );
683 Connector
* pCon
= mConnections
.GetObject( nItemId
- mnPopupStaticItems
- 1);
686 // mpDepperDontuseme->RemoveConnector( pCon->GetStartId(), pCon->GetEndId());
687 // TBD: CallEventListener
694 /*****************************************************************************/
695 IMPL_LINK( ObjectWin
, TipHdl
, void *, EMTY_ARG
)
696 /*****************************************************************************/
700 if ( msTipText
.Len()) {
701 Point
aPos( GetpApp()->GetAppWindow()->GetPointerPosPixel());
702 Help::ShowBalloon( GetpApp()->GetAppWindow(),
703 Point( aPos
.X(), aPos
.Y()),
704 String( msTipText
, RTL_TEXTENCODING_UTF8
));
709 /*****************************************************************************/
710 //void ObjectWin::GetFocus()
711 /*****************************************************************************/
713 //SetMarkMode( MARKMODE_SELECTED );
716 /*****************************************************************************/
717 void ObjectWin::LoseFocus()
718 /*****************************************************************************/
720 if ( !mbMenuExecute
&& !msbHideMode
) {
721 UnsetMarkMode( MARKMODE_SELECTED
);
722 UnsetMarkMode( MARKMODE_ACTIVATED
);
724 MarkDepending( TRUE
);
727 mbMenuExecute
= FALSE
;
730 /*****************************************************************************/
731 IMPL_LINK( ObjectWin
, PopupDeactivated
, PopupMenu
*, mpPopup_l
)
732 /*****************************************************************************/
734 mbMenuExecute
= FALSE
;
737 UnsetMarkMode( MARKMODE_SELECTED
);
738 UnsetMarkMode( MARKMODE_ACTIVATED
);
740 MarkDepending( TRUE
);
746 /*****************************************************************************/
747 void ObjectWin::Command( const CommandEvent
& rEvent
)
748 /*****************************************************************************/
750 fprintf(stdout
, "ObjectWin::Command");
751 // mpDepperDontuseme->GetGraphWin()->Command( rEvent );
752 // TBD: CallEventListener
756 /*****************************************************************************/
757 /*****************************************************************************/
759 ObjectList::ObjectList() : ObjWinList()
763 /*****************************************************************************/
764 void ObjectList::ResetSelectedObject()
765 /*****************************************************************************/
769 ULONG nCount_l
= Count();
770 ObjectWin
* pObjectWin
= NULL
;
771 for (ULONG i
=0; i
< nCount_l
; i
++ )
773 pObjectWin
= GetObject( i
);
774 pObjectWin
->UnsetMarkMode( MARKMODE_SELECTED
);
775 pObjectWin
->UnsetMarkMode( MARKMODE_NEEDED
);
776 pObjectWin
->UnsetMarkMode( MARKMODE_DEPENDING
);
777 pObjectWin
->SetActualWallpaper(*pDefaultWallpaper
);
778 pObjectWin
->SetAllConnectorsUnvisible();
783 /*****************************************************************************/
784 ObjectWin
* ObjectList::GetPtrByName( const ByteString
& rText
)
785 /*****************************************************************************/
788 ULONG nCount_l
= Count();
789 ObjectWin
* pObjectWin
= NULL
;
790 while ( i
< nCount_l
)
792 pObjectWin
= GetObject( i
);
793 ByteString sPrj
= pObjectWin
->GetBodyText();
794 if (sPrj
== rText
) return pObjectWin
;