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: depper.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 ************************************************************************/
33 #include <tools/stream.hxx>
34 #include <tools/debug.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <svtools/prgsbar.hxx>
38 #include <soldep/depper.hxx>
39 #include <soldep/objwin.hxx>
44 #include "dtsodcmp.hrc"
46 #include <vcl/svapp.hxx>
48 #define MIN(a,b) (a)<(b)?(a):(b)
49 #define MAX(a,b) (a)>(b)?(a):(b)
51 ByteString
sDelimiterLine("#==========================================================================");
56 Depper::Depper( Window
* pBaseWindow
):
57 Window( pBaseWindow
),
66 maArrangeDlg( pBaseWindow
),
67 mpPrjIdMapper( NULL
),
68 maToolBox( pBaseWindow
, DtSodResId(TID_SOLDEP_MAIN
) ),
69 maTaskBarFrame( pBaseWindow
, 0)
73 mpProcessWin
= pBaseWindow
;
74 mpGraphWin
= new GraphWin( mpProcessWin
, this );
75 mpGraphPrjWin
= new GraphWin( mpProcessWin
, this );
76 //mpBaseWin paints into virtual OutputDevice
77 mpBaseWin
= new DepWin( mpGraphWin
->GetBufferWindow(), WB_NOBORDER
| WB_SIZEABLE
| WB_AUTOSIZE
);
78 mpBasePrjWin
= new DepWin( mpGraphPrjWin
->GetBufferWindow(), WB_NOBORDER
| WB_SIZEABLE
| WB_AUTOSIZE
);
80 mpGraphWin
->SetBackground( Wallpaper( Color( COL_RED
)));
81 mpGraphPrjWin
->SetBackground( Wallpaper( Color( COL_BLUE
)));
82 mpGraphPrjWin
->Hide();
83 mpBaseWin
->SetBackground( Wallpaper( Color( COL_WHITE
)));
84 mpBasePrjWin
->SetBackground( Wallpaper( Color( COL_LIGHTGRAY
)));
86 mpGraphWin->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
87 mpGraphPrjWin->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
88 mpBaseWin->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
90 mpGraphWin
->EnableClipSiblings();
91 mpGraphPrjWin
->EnableClipSiblings();
93 mpParentProcessWin
= mpProcessWin
->GetParent();
97 mpBaseWin
->SetPopupHdl( this );
98 mpBasePrjWin
->SetPopupHdl( this );
100 mpObjectList
= new ObjectList(); //ObjectList unbekannt
101 mpObjectPrjList
= new ObjectList();
106 // delete mpObjectList;
111 BOOL
Depper::TogglePrjViewStatus()
113 GetDepWin()->Hide(); //Hide old content window
114 GetGraphWin()->Hide();
115 mbIsPrjView
= !mbIsPrjView
; //switch now
116 GetDepWin()->Invalidate();
117 GetGraphWin()->Show();
118 GetDepWin()->Show(); //Show new content window
122 void Depper::HideObjectsAndConnections( ObjectList
* pObjLst
)
124 for ( ULONG i
= 0; i
< pObjLst
->Count(); i
++ ) {
125 ObjectWin
*pWin
= pObjLst
->GetObject( i
);
130 mpGraphPrjWin
->Show();
131 mpBasePrjWin
->Show();
134 void Depper::ShowObjectsAndConnections( ObjectList
* pObjLst
)
136 for ( ULONG i
= 0; i
< pObjLst
->Count(); i
++ ) {
137 ObjectWin
*pWin
= pObjLst
->GetObject( i
);
140 mpBasePrjWin
->Hide();
141 mpGraphPrjWin
->Hide();
147 void Depper::RemoveAllObjects( ObjectList
* pObjLst
)
151 for ( i
= pObjLst
->Count(); i
> 0; i
-- )
152 delete pObjLst
->GetObject( i
- 1 );
156 USHORT
Depper::Save( const ByteString
& rFileName
)
158 DBG_ASSERT( FALSE
, "you are dead!" );
159 SvFileStream
aOutFile( String( rFileName
, RTL_TEXTENCODING_UTF8
), STREAM_WRITE
);
162 ULONG nObjCount
= mpObjectList
->Count();
164 ConnectorList
* pConList
= GetDepWin()->GetConnectorList();
165 ULONG nCnctrCount
= pConList
->Count();
168 dh
.nObjectCount
= nObjCount
;
169 dh
.nCnctrCount
= nCnctrCount
;
171 aOutFile
.Write( &dh
, sizeof( dh
));
173 for ( i
=0; i
< nObjCount
; i
++ )
175 mpObjectList
->GetObject( i
)->Save( aOutFile
);
178 for ( i
=0; i
< nCnctrCount
; i
++ )
180 pConList
->GetObject( i
)->Save( aOutFile
);
187 USHORT
Depper::WriteSource()
189 DBG_ASSERT( FALSE
, "overload it!" );
193 USHORT
Depper::ReadSource( BOOL bUpdater
)
195 DBG_ASSERT( FALSE
, "overload it!" );
199 USHORT
Depper::OpenSource()
201 DBG_ASSERT( FALSE
, "overload it!" );
205 ObjectWin
* Depper::ObjIdToPtr( ObjectList
* pObjLst
, ULONG nId
)
207 ULONG nObjCount
= pObjLst
->Count();
214 pWin
= pObjLst
->GetObject( i
);
215 nWinId
= pWin
->GetId();
218 while( i
< nObjCount
&& pWin
->GetId() != nId
);
219 if ( pWin
->GetId() == nId
)
225 void Depper::SetMainProgressBar( USHORT i
)
228 pMainBar
->SetValue( 100 );
233 void Depper::UpdateMainProgressBar(USHORT i
, USHORT nScaleVal
, USHORT
&nStep
, BOOL bCountingDown
)
237 // val = i * 50 / nScaleVal + 1;
238 val
= bCountingDown
? 50 + ( nScaleVal
- i
) * 50 / nScaleVal
: i
* 50 / nScaleVal
;
240 pMainBar
->SetValue( val
);
242 String
sText( String::CreateFromAscii( "Optimize step " ));
243 sText
+= String::CreateFromInt32( ++nStep
);
244 pSubText
->SetText( sText
);
248 void Depper::UpdateSubProgrssBar(ULONG i
)
252 pSubBar
->SetValue( i
);
254 GetpApp()->Reschedule();
259 USHORT
Depper::AutoArrangeDlgStart()
261 pSubBar
= maArrangeDlg
.GetSubBar();
262 pMainBar
= maArrangeDlg
.GetMainBar();
263 pSubText
= maArrangeDlg
.GetSubText();
264 pMainText
= maArrangeDlg
.GetMainText();
265 pMainText
->SetText( String::CreateFromAscii( "Overall status" ));
267 GetDepWin()->Enable( FALSE
);
272 USHORT
Depper::AutoArrangeDlgStop()
275 GetDepWin()->Enable( TRUE
);
286 USHORT
Depper::Zoom( MapMode
& rMapMode
)
292 ObjectList
* pObjList
;
293 pObjList
= GetObjectList();
294 // aSize = mpBaseWin->GetSizePixel();
295 // mpGraphWin->SetTotalSize( aSize );
296 // mpGraphWin->EndScroll( 0, 0 );
298 for ( i
= pObjList
->Count(); i
> 0; i
-- )
300 pWin
= pObjList
->GetObject( i
- 1 );
301 aPos
= pWin
->PixelToLogic( pWin
->GetPosPixel());
302 aSize
= pWin
->PixelToLogic( pWin
->GetSizePixel());
303 pWin
->SetMapMode( rMapMode
);
304 aPos
= pWin
->LogicToPixel( aPos
);
305 aSize
= pWin
->LogicToPixel( aSize
);
306 pWin
->SetPosSizePixel( aPos
, aSize
);
308 GetDepWin()->Invalidate();
312 ULONG
Depper::AddObjectToList( DepWin
* pParentWin
, ObjectList
* pObjLst
, ULONG
&LastID
, ULONG
&WinCount
, ByteString
& rBodyText
, BOOL bInteract
)
315 Size aSize
= GetDefSize();
317 aPos
= GetDepWin()->LogicToPixel( aPos
);
318 aSize
= GetDepWin()->LogicToPixel( aSize
);
319 return AddObjectToList( pParentWin
, pObjLst
, LastID
, WinCount
, rBodyText
, aPos
, aSize
);
322 ULONG
Depper::AddObjectToList( DepWin
* pParentWin
, ObjectList
* pObjLst
, ULONG
&LastID
, ULONG
&WinCount
, ByteString
& rBodyText
, Point
& rPos
, Size
& rSize
)
324 ObjectWin
* pWin
= new ObjectWin( pParentWin
, WB_BORDER
);
325 //pWin->mpDepperDontuseme = this;
326 pWin
->SetGlobalViewMask(mnViewMask
); // Set ViewMask for all ObjectWin and Connector objects
329 aNewSize
.Width() = pWin
->GetTextWidth( String( rBodyText
, RTL_TEXTENCODING_UTF8
));
330 aNewSize
.Height() = pWin
->GetTextHeight();
331 if ( aNewSize
.Width() > rSize
.Width() - 8 )
333 aNewSize
.Width() = aNewSize
.Width() + 8;
334 aNewSize
.Height() = rSize
.Height();
338 pWin
->SetPosSizePixel( rPos
,aNewSize
);
340 MapMode aMapMode
= mpBaseWin
->GetMapMode();
341 pWin
->SetMapMode( aMapMode
);
343 pObjLst
->Insert( pWin
, LIST_APPEND
);
344 pWin
->SetId( LastID
);
347 pWin
->SetBodyText( rBodyText
);
349 return pWin
->GetId();
352 /*void Depper::DrawOutput( OutputDevice* pDevice )
354 GetDepWin()->DrawOutput( pDevice );
355 ObjectList* pObjList = GetObjectList();
356 for ( USHORT i = pObjList->Count(); i > 0; i-- )
358 ObjectWin* pWin = pObjList->GetObject( i - 1 );
359 pWin->DrawOutput( pDevice );
363 ObjectWin
* Depper::RemoveObjectFromList( ObjectList
* pObjLst
, ULONG
&WinCount
, USHORT nId
, BOOL bDelete
)
365 ObjectWin
* pWin
= ObjIdToPtr( pObjLst
, nId
);
369 pObjLst
->Remove( pWin
);
378 USHORT
Depper::AddConnectorToObjects( ObjectList
* pObjLst
, ULONG nStartId
, ULONG nEndId
)
380 ObjectWin
* pStartWin
= ObjIdToPtr( pObjLst
, nStartId
);
383 return DEP_STARTID_NOT_FOUND
;
385 ObjectWin
* pEndWin
= ObjIdToPtr( pObjLst
, nEndId
);
388 return DEP_STARTID_NOT_FOUND
;
390 return AddConnectorToObjects( pStartWin
, pEndWin
);
393 USHORT
Depper::RemoveConnectorFromObjects( ObjectList
* pObjLst
, ULONG nStartId
, ULONG nEndId
)
395 // DBG_ASSERT( FALSE , "noch nicht" );
396 ObjectWin
* pStartWin
= ObjIdToPtr( pObjLst
, nStartId
);
399 return DEP_STARTID_NOT_FOUND
;
401 ObjectWin
* pEndWin
= ObjIdToPtr( pObjLst
, nEndId
);
404 return DEP_STARTID_NOT_FOUND
;
406 return RemoveConnectorFromObjects( pStartWin
, pEndWin
);
409 USHORT
Depper::AddConnectorToObjects( ObjectWin
* pStartWin
, ObjectWin
* pEndWin
)
411 if ( pStartWin
->ConnectionExistsInAnyDirection( pEndWin
))
414 Connector
* pCon
= new Connector( GetDepWin(), WB_NOBORDER
);
415 // pCon->Initialize( pStartWin, pEndWin );
416 if (pStartWin
->IsNullObject()) //null_project
417 pCon
->Initialize( pStartWin
, pEndWin
, FALSE
);
419 pCon
->Initialize( pStartWin
, pEndWin
, TRUE
);
423 USHORT
Depper::RemoveConnectorFromObjects( ObjectWin
* pStartWin
, ObjectWin
* pEndWin
)
425 Connector
* pCon
= pStartWin
->GetConnector( pStartWin
->GetId(), pEndWin
->GetId() );
428 return DEP_CONNECTOR_NOT_FOUND
;
436 ULONG
Depper::HandleNewPrjDialog( ByteString
&rBodyText
)
438 SolNewProjectDlg
aNewProjectDlg( GetDepWin(), DtSodResId( RID_SD_DIALOG_NEWPROJECT
));
439 if ( aNewProjectDlg
.Execute() )
441 rBodyText
= ByteString( aNewProjectDlg
.maEName
.GetText(), RTL_TEXTENCODING_UTF8
);
442 //hashtable auf stand halten
443 MyHashObject
* pHObject
;
444 ULONG nObjectId
= AddObjectToList( mpBaseWin
, mpObjectList
, mnSolLastId
, mnSolWinCount
, rBodyText
, FALSE
);
445 pHObject
= new MyHashObject( nObjectId
, ObjIdToPtr( mpObjectList
, nObjectId
));
446 mpSolIdMapper
->Insert( rBodyText
, pHObject
);
448 ByteString
sTokenLine( aNewProjectDlg
.maEShort
.GetText(), RTL_TEXTENCODING_UTF8
);
450 sTokenLine
+= ByteString( aNewProjectDlg
.maEName
.GetText(), RTL_TEXTENCODING_UTF8
);
451 sTokenLine
+= "\t:\t";
453 ByteString sDeps
= ByteString( aNewProjectDlg
.maEDeps
.GetText(), RTL_TEXTENCODING_UTF8
);
459 USHORT nToken
= sDeps
.GetTokenCount(' ');
460 for ( i
= 0 ; i
< nToken
; i
++)
462 sDepName
= sDeps
.GetToken( i
, ' ' );
463 sTokenLine
+= sDepName
;
469 mpStarWriter
->InsertTokenLine( sTokenLine
);
470 mpStarWriter
->InsertTokenLine( sDelimiterLine
);
476 ULONG nObjectId_l
, nHashedId
;
477 MyHashObject
* pHObject_l
;
478 USHORT nToken
= sDeps
.GetTokenCount(' ');
479 for ( i
= 0 ; i
< nToken
; i
++)
481 sDepName
= sDeps
.GetToken( i
, ' ' );
483 pHObject_l
= mpSolIdMapper
->Find( sDepName
);
487 sMessage
+= String::CreateFromAscii("can't find ");
488 sMessage
+= String( sDepName
, RTL_TEXTENCODING_UTF8
);
489 sMessage
+= String::CreateFromAscii(".\ndependency ignored");
490 WarningBox
aBox( GetDepWin(), WB_OK
, sMessage
);
495 nHashedId
= pHObject_l
->GetId();
496 pHObject_l
= mpSolIdMapper
->Find( rBodyText
);
497 nObjectId_l
= pHObject_l
->GetId();
498 AddConnectorToObjects( mpObjectList
, nHashedId
, nObjectId_l
);
507 ULONG
Depper::HandleNewDirectoryDialog(ByteString
&rBodyText
)
509 SolNewDirectoryDlg
aNewDirectoryDlg( GetDepWin(), DtSodResId( RID_SD_DIALOG_NEWDIRECTORY
));
511 if ( aNewDirectoryDlg
.Execute() )
513 rBodyText
= ByteString( aNewDirectoryDlg
.maEFlag
.GetText(), RTL_TEXTENCODING_UTF8
);
514 //hashtable auf stand halten
515 MyHashObject
* pHObject
;
516 ULONG nObjectId
= AddObjectToList( GetDepWin(), mpObjectPrjList
, mnSolLastId
, mnSolWinCount
, rBodyText
);
517 pHObject
= new MyHashObject( nObjectId
, ObjIdToPtr( mpObjectPrjList
, nObjectId
));
518 mpPrjIdMapper
->Insert( rBodyText
, pHObject
); // mpPrjIdMapper
521 sTokenLine
= String( mpPrj
->GetPreFix(), RTL_TEXTENCODING_UTF8
);
523 String sNameConvert
= aNewDirectoryDlg
.maEName
.GetText();
524 sNameConvert
.SearchAndReplaceAll( '/', '\\' );
525 if ( sNameConvert
.GetToken( 0, 0x5c ) != String( mpPrj
->GetProjectName(), RTL_TEXTENCODING_UTF8
))
527 sTokenLine
+= String( mpPrj
->GetProjectName(), RTL_TEXTENCODING_UTF8
);
528 sTokenLine
+= String("\\", RTL_TEXTENCODING_UTF8
);
529 sTokenLine
+= sNameConvert
;
532 sTokenLine
+= sNameConvert
;
534 sTokenLine
+= aNewDirectoryDlg
.maEAction
.GetText();
535 sTokenLine
+= String( "\t-\t", RTL_TEXTENCODING_UTF8
);
536 sTokenLine
+= aNewDirectoryDlg
.maEEnv
.GetText();
538 sTokenLine
+= aNewDirectoryDlg
.maEFlag
.GetText();
541 sTokenLine
+= String( "NULL", RTL_TEXTENCODING_UTF8
);
543 ByteString bsTokenLine
= ByteString( sTokenLine
, RTL_TEXTENCODING_UTF8
);
544 mpStarWriter
->InsertTokenLine( bsTokenLine
);
546 if ( aNewDirectoryDlg
.maEDeps
.GetText() != String( "", RTL_TEXTENCODING_UTF8
))
549 ByteString sDeps
= ByteString( aNewDirectoryDlg
.maEDeps
.GetText(), RTL_TEXTENCODING_UTF8
);
551 ULONG nObjectId_l
, nHashedId
;
552 MyHashObject
* pHObject_l
;
553 USHORT nToken
= sDeps
.GetTokenCount(' ');
554 for ( i
= 0 ; i
< nToken
; i
++)
556 sDepName
= sDeps
.GetToken( i
, ' ' );
558 pHObject_l
= mpPrjIdMapper
->Find( sDepName
); // mpPrjIdMapper
562 sMessage
+= String::CreateFromAscii("can't find ");
563 sMessage
+= String( sDepName
, RTL_TEXTENCODING_UTF8
);
564 sMessage
+= String::CreateFromAscii(".\ndependency ignored");
565 WarningBox
aBox( mpBaseWin
, WB_OK
, sMessage
);
570 sTokenLine
+= String( sDepName
, RTL_TEXTENCODING_UTF8
);
572 nHashedId
= pHObject_l
->GetId();
573 pHObject_l
= mpPrjIdMapper
->Find( rBodyText
); // mpPrjIdMapper
574 nObjectId_l
= pHObject_l
->GetId();
575 AddConnectorToObjects( mpObjectPrjList
, nHashedId
, nObjectId_l
);
580 if ( mpPrj
->Count() > 1 )
582 CommandData
* pData
= mpPrj
->GetObject( mpPrj
->Count() - 1 );
583 pData
= mpPrj
->Replace( pData
, mpPrj
->Count() - 2 );
584 mpPrj
->Replace( pData
, mpPrj
->Count() - 1 );
593 IMPL_LINK( Depper
, PopupSelected
, PopupMenu
*, mpPopup
)
595 USHORT nItemId
= mpPopup
->GetCurItemId();
601 ByteString sNewItem
= ByteString("new");
602 //AddObject( mpObjectList, sNewItem , TRUE );
605 case DEPPOPUP_AUTOARRANGE
:
606 //AutoArrange( mpObjectList, mpObjectList, GetStart(), 0 );
609 //Load( ByteString("test.dep"));
612 Save( ByteString("test.dep"));
614 case DEPPOPUP_WRITE_SOURCE
:
617 case DEPPOPUP_READ_SOURCE
:
620 case DEPPOPUP_OPEN_SOURCE
:
623 case DEPPOPUP_ZOOMIN
:
625 // DBG_ASSERT( FALSE,"zoomin");
626 MapMode aMapMode
= GetDepWin()->GetMapMode();
627 aMapMode
.SetScaleX( aMapMode
.GetScaleX() * Fraction( 1.25 ));
628 aMapMode
.SetScaleY( aMapMode
.GetScaleY() * Fraction( 1.25 ));
629 GetDepWin()->SetMapMode( aMapMode
);
633 Size
aZoomInSize( GetDepWin()->GetSizePixel());
634 aZoomInSize
.Width() *= 1.25;
635 aZoomInSize
.Height() *= 1.25;
636 GetDepWin()->SetSizePixel( aZoomInSize
);
643 case DEPPOPUP_ZOOMOUT
:
645 // DBG_ASSERT( FALSE,"zoomout");
646 MapMode aMapMode
= GetDepWin()->GetMapMode();
647 if ( aMapMode
.GetScaleX() > Fraction( 0.25 ))
649 aMapMode
.SetScaleX( aMapMode
.GetScaleX() * Fraction( 0.8 ));
650 aMapMode
.SetScaleY( aMapMode
.GetScaleY() * Fraction( 0.8 ));
651 GetDepWin()->SetMapMode( aMapMode
);
655 Size
aZoomOutSize( mpBaseWin
->GetSizePixel());
656 aZoomOutSize
.Width() *= 0.8;
657 aZoomOutSize
.Height() *= 0.8;
658 GetDepWin()->SetSizePixel( aZoomOutSize
);
666 case DEPPOPUP_CLEAR
:
667 // DBG_ASSERT( FALSE,"clear");
668 // RemoveAllObjects( mpObjectList );
670 case DEPPOPUP_CLOSE
:
671 // DBG_ASSERT( FALSE,"close");
675 // DBG_ASSERT( FALSE,"help");
679 // DBG_ASSERT( FALSE,"TEST!");
682 case DEPPOPUP_SHOW_TOOLBOX
:
686 DBG_ASSERT( FALSE
, "default" );