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 ************************************************************************/
30 #include <tools/stream.hxx>
31 #include <tools/debug.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <svtools/prgsbar.hxx>
35 #include <soldep/depper.hxx>
36 #include <soldep/objwin.hxx>
41 #include "dtsodcmp.hrc"
43 #include <vcl/svapp.hxx>
45 #define MIN(a,b) (a)<(b)?(a):(b)
46 #define MAX(a,b) (a)>(b)?(a):(b)
48 ByteString
sDelimiterLine("#==========================================================================");
53 Depper::Depper( Window
* pBaseWindow
):
54 Window( pBaseWindow
),
63 maArrangeDlg( pBaseWindow
),
64 mpPrjIdMapper( NULL
),
65 maToolBox( pBaseWindow
, DtSodResId(TID_SOLDEP_MAIN
) ),
66 maTaskBarFrame( pBaseWindow
, 0)
70 mpProcessWin
= pBaseWindow
;
71 mpGraphWin
= new GraphWin( mpProcessWin
, this );
72 mpGraphPrjWin
= new GraphWin( mpProcessWin
, this );
73 //mpBaseWin paints into virtual OutputDevice
74 mpBaseWin
= new DepWin( mpGraphWin
->GetBufferWindow(), WB_NOBORDER
| WB_SIZEABLE
| WB_AUTOSIZE
);
75 mpBasePrjWin
= new DepWin( mpGraphPrjWin
->GetBufferWindow(), WB_NOBORDER
| WB_SIZEABLE
| WB_AUTOSIZE
);
77 mpGraphWin
->SetBackground( Wallpaper( Color( COL_RED
)));
78 mpGraphPrjWin
->SetBackground( Wallpaper( Color( COL_BLUE
)));
79 mpGraphPrjWin
->Hide();
80 mpBaseWin
->SetBackground( Wallpaper( Color( COL_WHITE
)));
81 mpBasePrjWin
->SetBackground( Wallpaper( Color( COL_LIGHTGRAY
)));
83 mpGraphWin->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
84 mpGraphPrjWin->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
85 mpBaseWin->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
87 mpGraphWin
->EnableClipSiblings();
88 mpGraphPrjWin
->EnableClipSiblings();
90 mpParentProcessWin
= mpProcessWin
->GetParent();
94 mpBaseWin
->SetPopupHdl( this );
95 mpBasePrjWin
->SetPopupHdl( this );
97 mpObjectList
= new ObjectList(); //ObjectList unbekannt
98 mpObjectPrjList
= new ObjectList();
103 // delete mpObjectList;
108 BOOL
Depper::TogglePrjViewStatus()
110 GetDepWin()->Hide(); //Hide old content window
111 GetGraphWin()->Hide();
112 mbIsPrjView
= !mbIsPrjView
; //switch now
113 GetDepWin()->Invalidate();
114 GetGraphWin()->Show();
115 GetDepWin()->Show(); //Show new content window
119 void Depper::HideObjectsAndConnections( ObjectList
* pObjLst
)
121 for ( ULONG i
= 0; i
< pObjLst
->Count(); i
++ ) {
122 ObjectWin
*pWin
= pObjLst
->GetObject( i
);
127 mpGraphPrjWin
->Show();
128 mpBasePrjWin
->Show();
131 void Depper::ShowObjectsAndConnections( ObjectList
* pObjLst
)
133 for ( ULONG i
= 0; i
< pObjLst
->Count(); i
++ ) {
134 ObjectWin
*pWin
= pObjLst
->GetObject( i
);
137 mpBasePrjWin
->Hide();
138 mpGraphPrjWin
->Hide();
144 void Depper::RemoveAllObjects( ObjectList
* pObjLst
)
148 for ( i
= pObjLst
->Count(); i
> 0; i
-- )
149 delete pObjLst
->GetObject( i
- 1 );
153 USHORT
Depper::Save( const ByteString
& rFileName
)
155 DBG_ASSERT( FALSE
, "you are dead!" );
156 SvFileStream
aOutFile( String( rFileName
, RTL_TEXTENCODING_UTF8
), STREAM_WRITE
);
159 ULONG nObjCount
= mpObjectList
->Count();
161 ConnectorList
* pConList
= GetDepWin()->GetConnectorList();
162 ULONG nCnctrCount
= pConList
->Count();
165 dh
.nObjectCount
= nObjCount
;
166 dh
.nCnctrCount
= nCnctrCount
;
168 aOutFile
.Write( &dh
, sizeof( dh
));
170 for ( i
=0; i
< nObjCount
; i
++ )
172 mpObjectList
->GetObject( i
)->Save( aOutFile
);
175 for ( i
=0; i
< nCnctrCount
; i
++ )
177 pConList
->GetObject( i
)->Save( aOutFile
);
184 USHORT
Depper::WriteSource()
186 DBG_ASSERT( FALSE
, "overload it!" );
190 USHORT
Depper::ReadSource( BOOL bUpdater
)
192 DBG_ASSERT( FALSE
, "overload it!" );
196 USHORT
Depper::OpenSource()
198 DBG_ASSERT( FALSE
, "overload it!" );
202 ObjectWin
* Depper::ObjIdToPtr( ObjectList
* pObjLst
, ULONG nId
)
204 ULONG nObjCount
= pObjLst
->Count();
211 pWin
= pObjLst
->GetObject( i
);
212 nWinId
= pWin
->GetId();
215 while( i
< nObjCount
&& pWin
->GetId() != nId
);
216 if ( pWin
->GetId() == nId
)
222 void Depper::SetMainProgressBar( USHORT i
)
225 pMainBar
->SetValue( 100 );
230 void Depper::UpdateMainProgressBar(USHORT i
, USHORT nScaleVal
, USHORT
&nStep
, BOOL bCountingDown
)
234 // val = i * 50 / nScaleVal + 1;
235 val
= bCountingDown
? 50 + ( nScaleVal
- i
) * 50 / nScaleVal
: i
* 50 / nScaleVal
;
237 pMainBar
->SetValue( val
);
239 String
sText( String::CreateFromAscii( "Optimize step " ));
240 sText
+= String::CreateFromInt32( ++nStep
);
241 pSubText
->SetText( sText
);
245 void Depper::UpdateSubProgrssBar(ULONG i
)
249 pSubBar
->SetValue( i
);
251 GetpApp()->Reschedule();
256 USHORT
Depper::AutoArrangeDlgStart()
258 pSubBar
= maArrangeDlg
.GetSubBar();
259 pMainBar
= maArrangeDlg
.GetMainBar();
260 pSubText
= maArrangeDlg
.GetSubText();
261 pMainText
= maArrangeDlg
.GetMainText();
262 pMainText
->SetText( String::CreateFromAscii( "Overall status" ));
264 GetDepWin()->Enable( FALSE
);
269 USHORT
Depper::AutoArrangeDlgStop()
272 GetDepWin()->Enable( TRUE
);
283 USHORT
Depper::Zoom( MapMode
& rMapMode
)
289 ObjectList
* pObjList
;
290 pObjList
= GetObjectList();
291 // aSize = mpBaseWin->GetSizePixel();
292 // mpGraphWin->SetTotalSize( aSize );
293 // mpGraphWin->EndScroll( 0, 0 );
295 for ( i
= pObjList
->Count(); i
> 0; i
-- )
297 pWin
= pObjList
->GetObject( i
- 1 );
298 aPos
= pWin
->PixelToLogic( pWin
->GetPosPixel());
299 aSize
= pWin
->PixelToLogic( pWin
->GetSizePixel());
300 pWin
->SetMapMode( rMapMode
);
301 aPos
= pWin
->LogicToPixel( aPos
);
302 aSize
= pWin
->LogicToPixel( aSize
);
303 pWin
->SetPosSizePixel( aPos
, aSize
);
305 GetDepWin()->Invalidate();
309 ULONG
Depper::AddObjectToList( DepWin
* pParentWin
, ObjectList
* pObjLst
, ULONG
&LastID
, ULONG
&WinCount
, ByteString
& rBodyText
, BOOL bInteract
)
312 Size aSize
= GetDefSize();
314 aPos
= GetDepWin()->LogicToPixel( aPos
);
315 aSize
= GetDepWin()->LogicToPixel( aSize
);
316 return AddObjectToList( pParentWin
, pObjLst
, LastID
, WinCount
, rBodyText
, aPos
, aSize
);
319 ULONG
Depper::AddObjectToList( DepWin
* pParentWin
, ObjectList
* pObjLst
, ULONG
&LastID
, ULONG
&WinCount
, ByteString
& rBodyText
, Point
& rPos
, Size
& rSize
)
321 ObjectWin
* pWin
= new ObjectWin( pParentWin
, WB_BORDER
);
322 //pWin->mpDepperDontuseme = this;
323 pWin
->SetGlobalViewMask(mnViewMask
); // Set ViewMask for all ObjectWin and Connector objects
326 aNewSize
.Width() = pWin
->GetTextWidth( String( rBodyText
, RTL_TEXTENCODING_UTF8
));
327 aNewSize
.Height() = pWin
->GetTextHeight();
328 if ( aNewSize
.Width() > rSize
.Width() - 8 )
330 aNewSize
.Width() = aNewSize
.Width() + 8;
331 aNewSize
.Height() = rSize
.Height();
335 pWin
->SetPosSizePixel( rPos
,aNewSize
);
337 MapMode aMapMode
= mpBaseWin
->GetMapMode();
338 pWin
->SetMapMode( aMapMode
);
340 pObjLst
->Insert( pWin
, LIST_APPEND
);
341 pWin
->SetId( LastID
);
344 pWin
->SetBodyText( rBodyText
);
346 return pWin
->GetId();
349 /*void Depper::DrawOutput( OutputDevice* pDevice )
351 GetDepWin()->DrawOutput( pDevice );
352 ObjectList* pObjList = GetObjectList();
353 for ( USHORT i = pObjList->Count(); i > 0; i-- )
355 ObjectWin* pWin = pObjList->GetObject( i - 1 );
356 pWin->DrawOutput( pDevice );
360 ObjectWin
* Depper::RemoveObjectFromList( ObjectList
* pObjLst
, ULONG
&WinCount
, USHORT nId
, BOOL bDelete
)
362 ObjectWin
* pWin
= ObjIdToPtr( pObjLst
, nId
);
366 pObjLst
->Remove( pWin
);
375 USHORT
Depper::AddConnectorToObjects( ObjectList
* pObjLst
, ULONG nStartId
, ULONG nEndId
)
377 ObjectWin
* pStartWin
= ObjIdToPtr( pObjLst
, nStartId
);
380 return DEP_STARTID_NOT_FOUND
;
382 ObjectWin
* pEndWin
= ObjIdToPtr( pObjLst
, nEndId
);
385 return DEP_STARTID_NOT_FOUND
;
387 return AddConnectorToObjects( pStartWin
, pEndWin
);
390 USHORT
Depper::RemoveConnectorFromObjects( ObjectList
* pObjLst
, ULONG nStartId
, ULONG nEndId
)
392 // DBG_ASSERT( FALSE , "noch nicht" );
393 ObjectWin
* pStartWin
= ObjIdToPtr( pObjLst
, nStartId
);
396 return DEP_STARTID_NOT_FOUND
;
398 ObjectWin
* pEndWin
= ObjIdToPtr( pObjLst
, nEndId
);
401 return DEP_STARTID_NOT_FOUND
;
403 return RemoveConnectorFromObjects( pStartWin
, pEndWin
);
406 USHORT
Depper::AddConnectorToObjects( ObjectWin
* pStartWin
, ObjectWin
* pEndWin
)
408 if ( pStartWin
->ConnectionExistsInAnyDirection( pEndWin
))
411 Connector
* pCon
= new Connector( GetDepWin(), WB_NOBORDER
);
412 // pCon->Initialize( pStartWin, pEndWin );
413 if (pStartWin
->IsNullObject()) //null_project
414 pCon
->Initialize( pStartWin
, pEndWin
, FALSE
);
416 pCon
->Initialize( pStartWin
, pEndWin
, TRUE
);
420 USHORT
Depper::RemoveConnectorFromObjects( ObjectWin
* pStartWin
, ObjectWin
* pEndWin
)
422 Connector
* pCon
= pStartWin
->GetConnector( pStartWin
->GetId(), pEndWin
->GetId() );
425 return DEP_CONNECTOR_NOT_FOUND
;
433 ULONG
Depper::HandleNewPrjDialog( ByteString
&rBodyText
)
435 SolNewProjectDlg
aNewProjectDlg( GetDepWin(), DtSodResId( RID_SD_DIALOG_NEWPROJECT
));
436 if ( aNewProjectDlg
.Execute() )
438 rBodyText
= ByteString( aNewProjectDlg
.maEName
.GetText(), RTL_TEXTENCODING_UTF8
);
439 //hashtable auf stand halten
440 MyHashObject
* pHObject
;
441 ULONG nObjectId
= AddObjectToList( mpBaseWin
, mpObjectList
, mnSolLastId
, mnSolWinCount
, rBodyText
, FALSE
);
442 pHObject
= new MyHashObject( nObjectId
, ObjIdToPtr( mpObjectList
, nObjectId
));
443 mpSolIdMapper
->Insert( rBodyText
, pHObject
);
445 ByteString
sTokenLine( aNewProjectDlg
.maEShort
.GetText(), RTL_TEXTENCODING_UTF8
);
447 sTokenLine
+= ByteString( aNewProjectDlg
.maEName
.GetText(), RTL_TEXTENCODING_UTF8
);
448 sTokenLine
+= "\t:\t";
450 ByteString sDeps
= ByteString( aNewProjectDlg
.maEDeps
.GetText(), RTL_TEXTENCODING_UTF8
);
456 USHORT nToken
= sDeps
.GetTokenCount(' ');
457 for ( i
= 0 ; i
< nToken
; i
++)
459 sDepName
= sDeps
.GetToken( i
, ' ' );
460 sTokenLine
+= sDepName
;
466 mpStarWriter
->InsertTokenLine( sTokenLine
);
467 mpStarWriter
->InsertTokenLine( sDelimiterLine
);
473 ULONG nObjectId_l
, nHashedId
;
474 MyHashObject
* pHObject_l
;
475 USHORT nToken
= sDeps
.GetTokenCount(' ');
476 for ( i
= 0 ; i
< nToken
; i
++)
478 sDepName
= sDeps
.GetToken( i
, ' ' );
480 pHObject_l
= mpSolIdMapper
->Find( sDepName
);
484 sMessage
+= String::CreateFromAscii("can't find ");
485 sMessage
+= String( sDepName
, RTL_TEXTENCODING_UTF8
);
486 sMessage
+= String::CreateFromAscii(".\ndependency ignored");
487 WarningBox
aBox( GetDepWin(), WB_OK
, sMessage
);
492 nHashedId
= pHObject_l
->GetId();
493 pHObject_l
= mpSolIdMapper
->Find( rBodyText
);
494 nObjectId_l
= pHObject_l
->GetId();
495 AddConnectorToObjects( mpObjectList
, nHashedId
, nObjectId_l
);
504 ULONG
Depper::HandleNewDirectoryDialog(ByteString
&rBodyText
)
506 SolNewDirectoryDlg
aNewDirectoryDlg( GetDepWin(), DtSodResId( RID_SD_DIALOG_NEWDIRECTORY
));
508 if ( aNewDirectoryDlg
.Execute() )
510 rBodyText
= ByteString( aNewDirectoryDlg
.maEFlag
.GetText(), RTL_TEXTENCODING_UTF8
);
511 //hashtable auf stand halten
512 MyHashObject
* pHObject
;
513 ULONG nObjectId
= AddObjectToList( GetDepWin(), mpObjectPrjList
, mnSolLastId
, mnSolWinCount
, rBodyText
);
514 pHObject
= new MyHashObject( nObjectId
, ObjIdToPtr( mpObjectPrjList
, nObjectId
));
515 mpPrjIdMapper
->Insert( rBodyText
, pHObject
); // mpPrjIdMapper
518 sTokenLine
= String( mpPrj
->GetPreFix(), RTL_TEXTENCODING_UTF8
);
520 String sNameConvert
= aNewDirectoryDlg
.maEName
.GetText();
521 sNameConvert
.SearchAndReplaceAll( '/', '\\' );
522 if ( sNameConvert
.GetToken( 0, 0x5c ) != String( mpPrj
->GetProjectName(), RTL_TEXTENCODING_UTF8
))
524 sTokenLine
+= String( mpPrj
->GetProjectName(), RTL_TEXTENCODING_UTF8
);
525 sTokenLine
+= String("\\", RTL_TEXTENCODING_UTF8
);
526 sTokenLine
+= sNameConvert
;
529 sTokenLine
+= sNameConvert
;
531 sTokenLine
+= aNewDirectoryDlg
.maEAction
.GetText();
532 sTokenLine
+= String( "\t-\t", RTL_TEXTENCODING_UTF8
);
533 sTokenLine
+= aNewDirectoryDlg
.maEEnv
.GetText();
535 sTokenLine
+= aNewDirectoryDlg
.maEFlag
.GetText();
538 sTokenLine
+= String( "NULL", RTL_TEXTENCODING_UTF8
);
540 ByteString bsTokenLine
= ByteString( sTokenLine
, RTL_TEXTENCODING_UTF8
);
541 mpStarWriter
->InsertTokenLine( bsTokenLine
);
543 if ( aNewDirectoryDlg
.maEDeps
.GetText() != String( "", RTL_TEXTENCODING_UTF8
))
546 ByteString sDeps
= ByteString( aNewDirectoryDlg
.maEDeps
.GetText(), RTL_TEXTENCODING_UTF8
);
548 ULONG nObjectId_l
, nHashedId
;
549 MyHashObject
* pHObject_l
;
550 USHORT nToken
= sDeps
.GetTokenCount(' ');
551 for ( i
= 0 ; i
< nToken
; i
++)
553 sDepName
= sDeps
.GetToken( i
, ' ' );
555 pHObject_l
= mpPrjIdMapper
->Find( sDepName
); // mpPrjIdMapper
559 sMessage
+= String::CreateFromAscii("can't find ");
560 sMessage
+= String( sDepName
, RTL_TEXTENCODING_UTF8
);
561 sMessage
+= String::CreateFromAscii(".\ndependency ignored");
562 WarningBox
aBox( mpBaseWin
, WB_OK
, sMessage
);
567 sTokenLine
+= String( sDepName
, RTL_TEXTENCODING_UTF8
);
569 nHashedId
= pHObject_l
->GetId();
570 pHObject_l
= mpPrjIdMapper
->Find( rBodyText
); // mpPrjIdMapper
571 nObjectId_l
= pHObject_l
->GetId();
572 AddConnectorToObjects( mpObjectPrjList
, nHashedId
, nObjectId_l
);
577 if ( mpPrj
->Count() > 1 )
579 CommandData
* pData
= mpPrj
->GetObject( mpPrj
->Count() - 1 );
580 pData
= mpPrj
->Replace( pData
, mpPrj
->Count() - 2 );
581 mpPrj
->Replace( pData
, mpPrj
->Count() - 1 );
590 IMPL_LINK( Depper
, PopupSelected
, PopupMenu
*, mpPopup
)
592 USHORT nItemId
= mpPopup
->GetCurItemId();
598 ByteString sNewItem
= ByteString("new");
599 //AddObject( mpObjectList, sNewItem , TRUE );
602 case DEPPOPUP_AUTOARRANGE
:
603 //AutoArrange( mpObjectList, mpObjectList, GetStart(), 0 );
606 //Load( ByteString("test.dep"));
609 Save( ByteString("test.dep"));
611 case DEPPOPUP_WRITE_SOURCE
:
614 case DEPPOPUP_READ_SOURCE
:
617 case DEPPOPUP_OPEN_SOURCE
:
620 case DEPPOPUP_ZOOMIN
:
622 // DBG_ASSERT( FALSE,"zoomin");
623 MapMode aMapMode
= GetDepWin()->GetMapMode();
624 aMapMode
.SetScaleX( aMapMode
.GetScaleX() * Fraction( 1.25 ));
625 aMapMode
.SetScaleY( aMapMode
.GetScaleY() * Fraction( 1.25 ));
626 GetDepWin()->SetMapMode( aMapMode
);
630 Size
aZoomInSize( GetDepWin()->GetSizePixel());
631 aZoomInSize
.Width() *= 1.25;
632 aZoomInSize
.Height() *= 1.25;
633 GetDepWin()->SetSizePixel( aZoomInSize
);
640 case DEPPOPUP_ZOOMOUT
:
642 // DBG_ASSERT( FALSE,"zoomout");
643 MapMode aMapMode
= GetDepWin()->GetMapMode();
644 if ( aMapMode
.GetScaleX() > Fraction( 0.25 ))
646 aMapMode
.SetScaleX( aMapMode
.GetScaleX() * Fraction( 0.8 ));
647 aMapMode
.SetScaleY( aMapMode
.GetScaleY() * Fraction( 0.8 ));
648 GetDepWin()->SetMapMode( aMapMode
);
652 Size
aZoomOutSize( mpBaseWin
->GetSizePixel());
653 aZoomOutSize
.Width() *= 0.8;
654 aZoomOutSize
.Height() *= 0.8;
655 GetDepWin()->SetSizePixel( aZoomOutSize
);
663 case DEPPOPUP_CLEAR
:
664 // DBG_ASSERT( FALSE,"clear");
665 // RemoveAllObjects( mpObjectList );
667 case DEPPOPUP_CLOSE
:
668 // DBG_ASSERT( FALSE,"close");
672 // DBG_ASSERT( FALSE,"help");
676 // DBG_ASSERT( FALSE,"TEST!");
679 case DEPPOPUP_SHOW_TOOLBOX
:
683 DBG_ASSERT( FALSE
, "default" );