xref: /aoo4110/main/soldep/source/soldep.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 //TBD: ToolBox handling prjview/back
24 
25 #include <osl/file.hxx>
26 #include <rtl/ustring.hxx>
27 #include <tools/debug.hxx>
28 #include <soldep/sstring.hxx>
29 #include <svtools/filedlg.hxx>
30 #include <tools/iparser.hxx>
31 #include <tools/geninfo.hxx>
32 #include <vcl/gdimtf.hxx>
33 #include <vcl/bitmap.hxx>
34 #include <soldep/appdef.hxx>
35 #include "time.h"
36 #include <soldep/depper.hxx>
37 #include <soldep/soldep.hxx>
38 #include <soldep/soldlg.hxx>
39 #include "dtsodcmp.hrc"
40 
41 IMPLEMENT_HASHTABLE_OWNER( SolIdMapper, ByteString, sal_uIntPtr* );
42 //IMPLEMENT_HASHTABLE_OWNER( PrjIdMapper, ByteString, sal_uIntPtr* );
43 #define EVENT_RESIZE                0x00000001
44 #define MIN(a,b) (a)<(b)?(a):(b)
45 #define MAX(a,b) (a)>(b)?(a):(b)
46 
47 
48 //ByteString sDelimiterLine("#==========================================================================");
49 
50 
51 //
52 // class SolDep
53 //
54 
55 /*****************************************************************************/
SolDep(Window * pBaseWindow)56 SolDep::SolDep( Window* pBaseWindow )
57 /*****************************************************************************/
58 				: Depper( pBaseWindow ),
59                 mbBServer(sal_False),
60                 mpTravellerList( NULL ),
61                 mbIsHide( sal_False )
62 {
63     mnSolWinCount = 0;
64 	mnSolLastId = 0;
65 //    mpPrjIdMapper = new SolIdMapper( 63997 );
66     maTaskBarFrame.EnableAlwaysOnTop();
67     maTaskBarFrame.Show();
68     maToolBox.SetPosSizePixel( Point( 0,0 ), Size( 1100,35 ));
69 	maToolBox.SetSelectHdl( LINK ( this, SolDep, ToolSelect ));
70     maToolBox.Show();
71 
72 	mpBaseWin->AddChildEventListener( LINK( this, SolDep, ChildWindowEventListener ));
73 
74     // Kontext-Menue (geh�rt zu soldep.cxx)
75     InitContextMenueMainWnd();
76     InitContextMenuePrjViewWnd( mpBasePrjWin );
77 }
78 
79 /*****************************************************************************/
~SolDep()80 SolDep::~SolDep()
81 /*****************************************************************************/
82 {
83     mpBaseWin->RemoveChildEventListener( LINK( this, SolDep, ChildWindowEventListener ) );
84 	delete mpSolIdMapper;
85 	delete mpStarWriter;
86 	delete mpStandLst;
87 }
88 
89 /*****************************************************************************/
Init()90 void SolDep::Init()
91 /*****************************************************************************/
92 {
93 	InformationParser aParser;
94 	String sStandLst( GetDefStandList(), RTL_TEXTENCODING_ASCII_US );
95 	mpStandLst = aParser.Execute( sStandLst );
96     ByteString aUpdater( getenv("UPDATER") );
97 	if ( mpStandLst && (aUpdater == "YES") ) {
98 		if ( GetVersion() )
99 			ReadSource( sal_True );
100 	} else
101 	{
102 		ReadSource();   // if stand.lst isn't available
103 	}
104 }
105 
106 /*****************************************************************************/
Init(ByteString & rVersion,GenericInformationList * pVersionList)107 void SolDep::Init( ByteString &rVersion, GenericInformationList *pVersionList )
108 /*****************************************************************************/
109 {
110     // Interface for bs
111     mbBServer=sal_True;
112 	if ( pVersionList )
113 		mpStandLst = new GenericInformationList( *pVersionList );
114 	else {
115 		InformationParser aParser;
116 		String sStandLst( GetDefStandList(), RTL_TEXTENCODING_ASCII_US );
117 		mpStandLst = aParser.Execute( sStandLst );
118 	}
119 	if ( mpStandLst ) {
120 		msVersionMajor = ByteString( rVersion );
121 		ReadSource(sal_True); //call from build server set UPDATER to TRUE
122 	}
123 }
124 
125 /*****************************************************************************/
IMPL_LINK(SolDep,ChildWindowEventListener,VclSimpleEvent *,pEvent)126 IMPL_LINK( SolDep, ChildWindowEventListener, VclSimpleEvent*, pEvent )
127 /*****************************************************************************/
128 {
129 	if ( pEvent && pEvent->ISA( VclWindowEvent ) )
130 	{
131 		ProcessChildWindowEvent( *static_cast< VclWindowEvent* >( pEvent ) );
132 	}
133 	return 0;
134 }
135 
136 
137 /*****************************************************************************/
ProcessChildWindowEvent(const VclWindowEvent & _rVclWindowEvent)138 void SolDep::ProcessChildWindowEvent( const VclWindowEvent& _rVclWindowEvent )
139 /*****************************************************************************/
140 {
141     Window* pChildWin = _rVclWindowEvent.GetWindow();
142 //    Window* pParentWin = pChildWin->GetParent();
143 //Resize();
144     if ( isAlive() )
145 		{
146             sal_uIntPtr id = _rVclWindowEvent.GetId();
147 			switch ( id )
148 			{
149 				case VCLEVENT_USER_MOUSEBUTTON_DOWN:
150 					{
151 						ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
152 						if( pObjWin )
153 						{
154                             // handle mouse click on ObjectWin object
155                             ObjectWin* pWin = (ObjectWin*) pChildWin;
156                             //GetObjectList()->ResetSelectedObject();
157                             if (IsHideMode())      // simple mouse click left
158                             {
159                                 pWin->CaptureMouse();
160 			                    pWin->SetMarkMode( MARKMODE_SELECTED );
161                                 pWin->MarkNeeded();
162                                 pWin->MarkDepending();
163                                 pWin->Invalidate();
164                             } else
165                             {
166                                 pWin->LoseFocus();
167                                 pWin->SetMarkMode( MARKMODE_SELECTED );
168                                 pWin->UnsetMarkMode( MARKMODE_ACTIVATED );
169 			                    pWin->MarkNeeded( sal_True );
170 			                    pWin->MarkDepending( sal_True );
171                             }
172 
173 						}
174 					}
175 					break;
176                 case VCLEVENT_USER_MOUSEBUTTON_DOWN_ALT:
177                     {
178                         ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
179 						if( pObjWin )
180 						{
181                             ObjectWin* pWin = (ObjectWin*) pChildWin;
182                             MarkObjects( pWin );
183                         }
184                     }
185                     break;
186                 case VCLEVENT_USER_MOUSEBUTTON_DOWN_DBLCLICK:
187                     {
188                         ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
189 						if( pObjWin )
190 						{
191 							if (IsHideMode()) ToggleHideDependency();
192                             ByteString text = ((ObjectWin*) pChildWin)->GetBodyText();
193                             ViewContent(text);
194                         }
195                     }
196                     break;
197                 case VCLEVENT_USER_MOUSEBUTTON_UP_SHFT:
198                     {
199                         ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
200 						if( pObjWin )
201 						{
202                             ObjectWin* pWin = (ObjectWin*) pChildWin;
203                             GetDepWin()->NewConnector( pWin );
204                         }
205                     }
206                     break;
207                 case VCLEVENT_USER_MOUSEBUTTON_UP:
208                      {
209                         ObjectWin* pObjWin = dynamic_cast<ObjectWin*>(pChildWin);
210 						if( pObjWin )
211 						{
212                             ObjectWin* pWin = (ObjectWin*) pChildWin;
213                 			pWin->ReleaseMouse();
214                             pWin->SetMarkMode(MARKMODE_SELECTED);
215                             GetDepWin()->Invalidate();
216                         }
217                      }
218                      break;
219 			}    // switch
220 		}  // if isAlive
221         //fprintf(stdout,"BLA::Resize: %d\n",pChildWin);
222 }
223 
224 /*****************************************************************************/
IMPL_LINK(SolDep,ToolSelect,SoldepToolBox *,pBox)225 IMPL_LINK( SolDep, ToolSelect, SoldepToolBox* , pBox)
226 /*****************************************************************************/
227 {
228 	sal_uInt16 nItemId = pBox->GetCurItemId();
229 	switch ( nItemId )
230 	{
231 		case TID_SOLDEP_FIND:
232 			FindProject();
233 			break;
234         case TID_SOLDEP_CREATEMETA :
235         {
236             VirtualDevice   aVDev;
237 			aVDev.SetMapMode( MAP_100TH_MM );
238             GDIMetaFile     aMtf;
239             aVDev.EnableOutput( sal_False );
240             aMtf.Record( &aVDev );
241 
242 			aVDev.SetLineColor( Color( COL_BLACK ) );
243 			aVDev.SetTextAlign( ALIGN_TOP );
244 
245 			Size aSize( GetDepWin()->GetOutputSizePixel() );
246 			long nXMin = aSize.Width();
247 			long nXMax = 0;
248 			long nYMax = 0;
249 			long nYMin = aSize.Height();
250 
251 			for ( sal_uInt16 i=0; i<mpObjectList->Count(); i++ )
252 			{
253 				Point aPoint = mpObjectList->GetObject(i)->GetPosPixel();
254 				Size aSize = mpObjectList->GetObject(i)->GetSizePixel();
255 				nXMin = MIN( aPoint.X(), nXMin );
256 				nXMax = MAX( aPoint.X() + aSize.Width(), nXMax );
257 				nYMin = MIN( aPoint.Y(), nYMin );
258 				nYMax = MAX( aPoint.Y() + aSize.Height(), nYMax );
259 			}
260 
261 			Point aOffset( nXMin, nYMin );
262 			aOffset = aVDev.PixelToLogic( aOffset );
263 
264             GetDepWin()->DrawOutput( &aVDev, aOffset );
265 			for ( sal_uInt16 i=0; i<mpObjectList->Count(); i++ )
266 				if ( mpObjectList->GetObject(i)->IsVisible() )
267 					mpObjectList->GetObject(i)->DrawOutput( &aVDev, aOffset );
268 
269             aMtf.Stop();
270             aMtf.WindStart();
271             aMtf.SetPrefMapMode( aVDev.GetMapMode() );
272 			Size aDevSize( nXMax-nXMin + 10, nYMax-nYMin + 10);
273 			aDevSize =	aVDev.PixelToLogic( aDevSize );
274             aMtf.SetPrefSize( aDevSize );
275 			SvFileStream aStream( String::CreateFromAscii("d:\\out.svm"), STREAM_STD_READWRITE );
276 			aMtf.Write( aStream );
277             break;
278         }
279 		case TID_SOLDEP_HIDE_INDEPENDEND:
280 			{
281                 ToggleHideDependency();
282 				for ( sal_uInt16 i=0; i<mpObjectList->Count(); i++ )
283 					mpObjectList->GetObject(i)->SetViewMask(!mbIsHide);
284 
285    	    	    maToolBox.CheckItem(TID_SOLDEP_HIDE_INDEPENDEND, IsHideMode());
286        	    	GetDepWin()->Invalidate(); //repaint Main-View
287 			}
288             break;
289         case TID_SOLDEP_SELECT_WORKSPACE:
290 			if (mpStandLst)
291 			{
292 				if (GetVersion()) // Version dialog box
293                 {
294                     delete mpSolIdMapper;
295 	                delete mpStarWriter;
296                     mpObjectList->ClearAndDelete();
297 				    ReadSource(sal_True);
298                 }
299 			}
300             break;
301         case TID_SOLDEP_BACK:
302             maToolBox.HideItem(TID_SOLDEP_BACK);
303 			maToolBox.ShowItem(TID_SOLDEP_SELECT_WORKSPACE);  //disabled for prj view (doubleclick ObjWin)
304             maToolBox.ShowItem(TID_SOLDEP_HIDE_INDEPENDEND);  //disabled for prj view (doubleclick ObjWin)
305             maToolBox.ShowItem(TID_SOLDEP_FIND);              //disabled for prj view (doubleclick ObjWin)
306             maToolBox.Resize();
307 			TogglePrjViewStatus();
308             break;
309 	}
310 	return 0;
311 }
312 
313 /*****************************************************************************/
ToggleHideDependency()314 void SolDep::ToggleHideDependency()
315 /*****************************************************************************/
316 {
317 	mbIsHide = !mbIsHide;
318 	maToolBox.CheckItem(TID_SOLDEP_HIDE_INDEPENDEND, IsHideMode());
319 	ObjectWin* pWin = GetObjectList()->GetObject( 0 );
320 	pWin->ToggleHideMode();
321 };
322 
323 /*****************************************************************************/
GetVersion()324 sal_Bool SolDep::GetVersion()
325 /*****************************************************************************/
326 {
327 	SolSelectVersionDlg aVersionDlg( GetDepWin(), mpStandLst );
328 	if ( aVersionDlg.Execute() == RET_OK ) {
329 		msVersionMajor = aVersionDlg.GetVersionMajor();
330         msVersionMinor = aVersionDlg.GetVersionMinor();
331 		return sal_True;
332 	}
333 	return sal_False;
334 }
335 
InitContextMenueMainWnd()336 void SolDep::InitContextMenueMainWnd()
337 {
338     InitContextMenuePrjViewWnd( mpBaseWin );
339     return; // Disable not actually supported items
340 
341     mpBaseWin->mpPopup->InsertItem( DEPPOPUP_AUTOARRANGE, String::CreateFromAscii("Autoarrange")) ;
342     mpBaseWin->mpPopup->InsertSeparator();
343 	mpBaseWin->mpPopup->InsertItem( DEPPOPUP_READ_SOURCE, String::CreateFromAscii("Revert all changes") );
344 	mpBaseWin->mpPopup->InsertSeparator();
345 	mpBaseWin->mpPopup->InsertItem( DEPPOPUP_OPEN_SOURCE, String::CreateFromAscii("Open") );
346 	mpBaseWin->mpPopup->InsertItem( DEPPOPUP_WRITE_SOURCE, String::CreateFromAscii("Save") );
347 }
348 
InitContextMenuePrjViewWnd(DepWin * pBaseWin)349 void SolDep::InitContextMenuePrjViewWnd(DepWin* pBaseWin )
350 {
351     // temp. disabled pBaseWin->mpPopup->InsertItem( DEPPOPUP_NEW, String::CreateFromAscii("New object") );
352 	pBaseWin->mpPopup->InsertItem( DEPPOPUP_ZOOMIN, String::CreateFromAscii("Zoom in") );
353 	pBaseWin->mpPopup->InsertItem( DEPPOPUP_ZOOMOUT, String::CreateFromAscii("Zoom out") );
354 	pBaseWin->mpPopup->InsertSeparator();
355 	// temp disabled pBaseWin->mpPopup->InsertItem( DEPPOPUP_CLEAR, String::CreateFromAscii("Clear") );
356     pBaseWin->mpPopup->InsertItem( DEPPOPUP_SHOW_TOOLBOX, String::CreateFromAscii("Show Toolbox") );
357 }
358 
359 /*****************************************************************************/
RemoveObject(sal_uInt16 nId,sal_Bool bDelete)360 ObjectWin *SolDep::RemoveObject( sal_uInt16 nId, sal_Bool bDelete )
361 /*****************************************************************************/
362 {
363 	Prj* pPrj;
364 
365 //hshtable auf stand halten
366 	ObjectWin* pWin = RemoveObjectFromList( mpObjectList, mnSolWinCount, nId, sal_False );
367 	if ( pWin )
368 	{
369 		ByteString aBodyText( pWin->GetBodyText() );
370 		if( (pPrj = mpStarWriter->GetPrj( aBodyText )) )
371 		{
372 			mpStarWriter->Remove( pPrj );
373 //cleanup ist teuer...
374 			mpStarWriter->CleanUp();
375 			delete pPrj;
376 		}
377 		else
378 			DBG_ASSERT( sal_False, "project not found - write" );
379 
380 		mpSolIdMapper->Delete( aBodyText );
381 		if ( bDelete )
382 			delete pWin;
383 		return pWin;
384 	}
385 	else
386 		return NULL;
387 }
388 
389 /*****************************************************************************/
AddObject(ByteString & rBodyText,sal_Bool bInteract)390 sal_uIntPtr SolDep::AddObject( ByteString& rBodyText, sal_Bool bInteract )
391 /*****************************************************************************/
392 {
393     sal_uIntPtr nObjectId;
394 	if ( bInteract )
395 	{
396 		nObjectId = HandleNewPrjDialog( rBodyText );
397 	}
398 	else
399 	{
400 //hashtable auf stand halten
401 		MyHashObject* pHObject;
402 		nObjectId = AddObjectToList( mpBaseWin, mpObjectList, mnSolLastId, mnSolWinCount, rBodyText, sal_False );
403 		pHObject = new MyHashObject( nObjectId, ObjIdToPtr(mpObjectList, nObjectId ));
404 		mpSolIdMapper->Insert( rBodyText, pHObject );
405 	}
406     return nObjectId;
407 }
408 
409 /*****************************************************************************/
AddPrjObject(ByteString & rBodyText,sal_Bool bInteract)410 sal_uIntPtr SolDep::AddPrjObject( ByteString& rBodyText, sal_Bool bInteract )
411 /*****************************************************************************/
412 {
413     sal_uIntPtr nObjectId;
414 	if ( bInteract )
415 	{
416         nObjectId = HandleNewDirectoryDialog( rBodyText );
417 	}
418 	else
419 	{
420 //hshtable auf stand halten
421 		MyHashObject* pHObject;
422 		nObjectId = AddObjectToList( mpBasePrjWin, mpObjectPrjList, mnPrjLastId, mnPrjWinCount, rBodyText );
423 		pHObject = new MyHashObject( nObjectId, ObjIdToPtr( mpObjectPrjList, nObjectId ));
424 		mpPrjIdMapper->Insert( rBodyText, pHObject ); // mpPrjIdMapper
425 	}
426     return nObjectId;
427 }
428 
429 /*****************************************************************************/
AddConnector(ObjectWin * pStartWin,ObjectWin * pEndWin)430 sal_uInt16 SolDep::AddConnector( ObjectWin* pStartWin, ObjectWin* pEndWin )
431 /*****************************************************************************/
432 {
433 //	DBG_ASSERT( FALSE , "not yet" );
434 	ByteString sEndName = pEndWin->GetBodyText();
435 	ByteString sStartName = pStartWin->GetBodyText();
436 
437 	Prj* pPrj = mpStarWriter->GetPrj( sEndName );
438 	if ( pPrj )
439 	{
440 		pPrj->AddDependencies( sStartName );
441 		return AddConnectorToObjects( pStartWin, pEndWin );
442 	}
443 	else
444 	{
445 		DBG_ASSERT( sal_False , "non existing Project" );
446 		return 1;
447 	}
448 }
449 
450 /*****************************************************************************/
RemoveConnector(ObjectWin * pStartWin,ObjectWin * pEndWin)451 sal_uInt16 SolDep::RemoveConnector( ObjectWin* pStartWin, ObjectWin* pEndWin )
452 /*****************************************************************************/
453 {
454 	SByteStringList* pPrjDeps = NULL;
455 	ByteString sEndName = pEndWin->GetBodyText();
456 	ByteString sStartName = pStartWin->GetBodyText();
457 
458 	Prj* pPrj = mpStarWriter->GetPrj( sEndName );
459 	pPrjDeps = pPrj->GetDependencies( sal_False );
460 	if ( pPrjDeps )
461 	{
462 		ByteString* pString;
463 		sal_uIntPtr nPrjDepsCount = pPrjDeps->Count();
464 		for ( sal_uIntPtr j = nPrjDepsCount; j > 0; j-- )
465 		{
466 			pString = pPrjDeps->GetObject( j - 1 );
467 			if ( pString->GetToken( 0, '.') == sStartName )
468 				pPrjDeps->Remove( pString );
469 		}
470 	}
471 
472 	return RemoveConnectorFromObjects( pStartWin, pEndWin );
473 }
474 
475 /*****************************************************************************/
RemoveAllObjects(ObjectList * pObjLst)476 void SolDep::RemoveAllObjects( ObjectList* pObjLst )
477 /*****************************************************************************/
478 {
479 
480 	Depper::RemoveAllObjects( pObjLst );
481 
482 	if ( mpSolIdMapper )
483 	{
484 		delete mpSolIdMapper;
485 		mpSolIdMapper = NULL;
486 	}
487 	if ( mpStarWriter )
488 	{
489 		delete mpStarWriter;
490 		mpStarWriter = NULL;
491 	}
492 }
493 
494 /*****************************************************************************/
GetStart(SolIdMapper * pIdMapper,ObjectList * pObjList)495 sal_uIntPtr SolDep::GetStart(SolIdMapper* pIdMapper, ObjectList* pObjList)
496 /*****************************************************************************/
497 {
498 //	DBG_ASSERT( FALSE , "soldep" );
499 	MyHashObject* pHObject = pIdMapper->Find( "null" );//null_project
500 
501 	if ( !pHObject ) {
502 		ByteString sNullPrj = "null";//null_project
503 		sal_uIntPtr nObjectId = AddObject( sNullPrj, sal_False );
504 		ObjIdToPtr( pObjList, nObjectId )->SetViewMask( 1 );
505 		return nObjectId;
506 	}
507 
508 	return pHObject->GetId();
509 }
510 
511 /*****************************************************************************/
GetStartPrj(SolIdMapper *,ObjectList *)512 sal_uIntPtr SolDep::GetStartPrj(SolIdMapper* , ObjectList* )
513 /*****************************************************************************/
514 {
515 //	DBG_ASSERT( FALSE , "prjdep" );
516 	MyHashObject* pHObject = mpPrjIdMapper->Find( ByteString( "null" ) ); //null_dir
517 	if ( !pHObject )
518 	{
519 		ByteString bsNull("null");
520 		sal_uIntPtr nObjectId = AddPrjObject( bsNull, sal_False); //null_dir
521 		return nObjectId;
522 	}
523 	else
524 		return pHObject->GetId();
525 }
526 
527 /*****************************************************************************/
OpenSource()528 sal_uInt16 SolDep::OpenSource()
529 /*****************************************************************************/
530 {
531 	if ( mpStandLst ) {
532 		if ( GetVersion())
533 			return ReadSource();
534 	}
535 	return 0;
536 }
537 
538 /*****************************************************************************/
ReadSource(sal_Bool bUpdater)539 sal_uInt16 SolDep::ReadSource(sal_Bool bUpdater)
540 /*****************************************************************************/
541 {
542 	mpBaseWin->EnablePaint( sal_False );
543     mpBaseWin->Hide();
544 	sal_uIntPtr nObjectId, nHashedId;
545 	sal_uIntPtr i;
546 	MyHashObject* pHObject;
547 	ByteString* pStr;
548 	ObjectWin *pStartWin, *pEndWin;
549 
550     mpSolIdMapper = new SolIdMapper( 63997 );
551     if (mpStandLst && bUpdater)
552     {
553         mpStarWriter = new StarWriter( mpStandLst, msVersionMajor, msVersionMinor, sal_True );
554     } else
555     {
556         SolarFileList* pSolarFileList;
557         pSolarFileList = GetPrjListFromDir();
558         mpStarWriter = new StarWriter( pSolarFileList, sal_True );
559     }
560 	ByteString sTitle( SOLDEPL_NAME );
561 	if ( mpStarWriter->GetMode() == STAR_MODE_SINGLE_PARSE ) {
562 		sTitle += ByteString( " - mode: single file [" );
563 	   	sTitle += (ByteString) mpStarWriter->GetName();
564 		sTitle += ByteString( "]" );
565 	}
566 	else if ( mpStarWriter->GetMode() == STAR_MODE_MULTIPLE_PARSE ) {
567 		sTitle += ByteString( " - mode: multiple files [" );
568 		sTitle += ByteString( "]" );
569 	}
570 	SetTitle( String( sTitle, RTL_TEXTENCODING_UTF8) );
571 
572 	sal_uIntPtr nCount = mpStarWriter->Count();
573 	for ( i=0; i<nCount; i++ )
574 	{
575 		Prj *pPrj = mpStarWriter->GetObject(i);
576 		ByteString sPrjName = pPrj->GetProjectName();
577 		nObjectId = AddObject( sPrjName, sal_False );
578 		ObjIdToPtr( mpObjectList, nObjectId )->SetViewMask( 1 );
579 	}
580 	for ( i=0; i<nCount; i++ )
581 	{
582 		Prj *pPrj = mpStarWriter->GetObject(i);
583 		SByteStringList *pLst = pPrj->GetDependencies( sal_False );
584 		if ( pLst )
585 		{
586 			sal_uIntPtr nDepCount = pLst->Count();
587 			for ( sal_uIntPtr m=0; m<nDepCount; m++)
588 			{
589 				pStr = pLst->GetObject(m);
590 				pHObject = mpSolIdMapper->Find( *pStr );
591 				/*if ( !pHObject )
592 				{
593 	// create new prj
594 					Prj *pNewPrj = new Prj( *pStr );
595 					ByteString sPrjName = pNewPrj->GetProjectName();
596 					nObjectId = AddObject( sPrjName, sal_False );
597 					pHObject = mpSolIdMapper->Find( *pStr );
598 					ObjIdToPtr( mpObjectList, nObjectId )->SetViewMask( 2 );
599 				}*/
600 
601 				if ( pHObject )
602 				{
603 				nHashedId = pHObject->GetId();
604 				ByteString sF_Os2 = pPrj->GetProjectName();
605 				pStr = &sF_Os2;
606 				pHObject = mpSolIdMapper->Find( *pStr );
607 				nObjectId = pHObject->GetId();
608 				pStartWin = ObjIdToPtr( mpObjectList, nHashedId );
609 				pEndWin = ObjIdToPtr( mpObjectList, nObjectId );
610 				AddConnectorToObjects( pStartWin, pEndWin );
611 			}
612 		}
613 	}
614 	}
615     if (!IsPrjView())
616     {
617 	    AutoArrange( mpSolIdMapper, mpObjectList, GetStart(mpSolIdMapper,mpObjectList), 0, GetStart(mpSolIdMapper,mpObjectList) );
618 	    GetDepWin()->EnablePaint( sal_True );
619     }
620 	return 0;
621 }
622 
GetPrjListFromDir()623 SolarFileList* SolDep::GetPrjListFromDir()
624 {
625     SolarFileList* pSolarFileList = new SolarFileList();
626     String sPrjDir( String::CreateFromAscii( "prj" ));
627 	String sBuildLst( String::CreateFromAscii( "build.lst" ));
628     DirEntry aCurrent( getenv( SOURCEROOT ) );
629 
630     aCurrent.ToAbs();
631     Dir aDir( aCurrent, FSYS_KIND_DIR );
632 
633 	sal_uInt16 nEntries = aDir.Count();
634 	if( nEntries )
635 	{
636 		UniStringList aSortDirList;
637 		for ( sal_uInt16 n = 0; n < nEntries; n++ )
638 		{
639 			DirEntry& rEntry = aDir[n];
640 			UniString aName( rEntry.GetName() );
641 			if( aName.Len() && ( aName.GetChar(0) != '.' ) && rEntry.Exists() )
642 			{
643                 rEntry += DirEntry( sPrjDir );
644                 rEntry += DirEntry( sBuildLst );
645                 if (rEntry.Exists())
646                 {
647                     pSolarFileList->Insert( new String( rEntry.GetFull() ), LIST_APPEND );
648                     ByteString aName_dbg(rEntry.GetFull(),RTL_TEXTENCODING_UTF8);
649                     fprintf(stdout, "bla:%s\n", aName_dbg.GetBuffer());
650                 }
651             }
652         }
653     }
654     if ( !pSolarFileList->Count() )
655     {
656          //is empty!! TBD
657          delete pSolarFileList;
658          return NULL;
659     }
660     return pSolarFileList;
661 }
662 
663 /*****************************************************************************/
WriteSource()664 sal_uInt16 SolDep::WriteSource()
665 /*****************************************************************************/
666 {
667 /* zur Sicherheit deaktiviert
668 	sal_uInt16 nMode = mpStarWriter->GetMode();
669 	if ( nMode == STAR_MODE_SINGLE_PARSE ) {
670 		ByteString sFileName = mpStarWriter->GetName();
671 		if ( sFileName.Len()) {
672 			mpStarWriter->Write( String( sFileName, RTL_TEXTENCODING_UTF8) );
673 			mpStarWriter->RemoveProject( ByteString( "null"));  //null_project
674 		}
675 	}
676 	else if ( nMode == STAR_MODE_MULTIPLE_PARSE ) {
677 	// *OBO*
678 	//String sRoot = mpStarWriter->GetSourceRoot();
679 	//nicht mehr unterst�tzt mpStarWriter->GetSourceRoot()
680 		ByteString sFileName = mpStarWriter->GetName();
681 		DirEntry aEntry( sFileName );
682 		aEntry.ToAbs();
683 		aEntry = aEntry.GetPath().GetPath().GetPath();
684 		String sRoot = aEntry.GetFull();
685 
686 		if ( sRoot.Len()) {
687 			mpStarWriter->RemoveProject( ByteString( "null")); //null_project
688 			mpStarWriter->WriteMultiple( sRoot );
689 		}
690 	}
691 */
692 	return 1;
693 }
694 
Load(const ByteString & rFileName)695 sal_uInt16 SolDep::Load( const ByteString& rFileName )
696 {
697 // moved from depper class
698 	DBG_ASSERT( sal_False , "you are dead!" );
699 	SvFileStream aInFile( String( rFileName, RTL_TEXTENCODING_UTF8 ), STREAM_READ );
700 	depper_head dh;
701 	sal_uIntPtr i;
702 	sal_uIntPtr nLoadOffs = mnSolLastId;     //or Prj??
703 	ObjectWin* pNewWin;
704 	aInFile.Read( &dh, sizeof( dh ));
705 
706 	sal_uIntPtr nObjCount = dh.nObjectCount;
707 	sal_uIntPtr nCnctrCount = dh.nCnctrCount;
708 
709 	for ( i=0; i < nObjCount ; i++ )
710 	{
711 		ObjectWin* pWin = new ObjectWin( mpBaseWin, WB_BORDER );
712 		pWin->Load( aInFile );
713 		pNewWin = ObjIdToPtr( mpObjectList, AddObjectToList( mpBaseWin, mpObjectList, mnSolLastId, mnSolWinCount, pWin->GetBodyText(), sal_False ));
714 		pNewWin->SetId( nLoadOffs + pWin->GetId());
715 		pNewWin->SetPosPixel( pWin->GetPosPixel());
716 		pNewWin->SetSizePixel( pWin->GetSizePixel());
717 	}
718 
719 	sal_uIntPtr nStartId;
720 	sal_uIntPtr nEndId;
721 //	ueber addconnector fuehren!
722 	for ( i=0; i < nCnctrCount ; i++ )
723 	{
724 		Connector* pCon = new Connector( mpBaseWin, WB_NOBORDER );
725 		pCon->Load( aInFile );
726 
727 		nStartId = nLoadOffs + pCon->GetStartId();
728 		nEndId = nLoadOffs + pCon->GetEndId();
729 
730 		ObjectWin* pStartWin = ObjIdToPtr( mpObjectList, nStartId );
731 		ObjectWin* pEndWin = ObjIdToPtr( mpObjectList, nEndId );
732 
733 		pCon->Initialize( pStartWin, pEndWin );
734 	}
735 
736 
737 	return 0;
738 }
739 
740 /*****************************************************************************/
ViewContent(ByteString & rObjectName)741 sal_Bool SolDep::ViewContent( ByteString& rObjectName )
742 /*****************************************************************************/
743 {
744 	mpFocusWin = NULL;
745 	SetPrjViewStatus(sal_True);
746 
747 	for ( sal_uIntPtr i = 0; i < mpObjectList->Count() && !mpFocusWin; i++ )
748 		if ( mpObjectList->GetObject( i )->HasFocus())
749 			mpFocusWin = mpObjectList->GetObject( i );
750     //HideObjectsAndConnections( mpObjectList );
751 	mpProcessWin->Resize();
752     GetDepWin()->Show();
753 	return InitPrj( rObjectName );
754 }
755 
756 /*****************************************************************************/
InitPrj(ByteString & rListName)757 sal_Bool SolDep::InitPrj( ByteString& rListName )
758 /*****************************************************************************/
759 {
760 	sal_uIntPtr nObjectId, nHashedId;
761 	sal_uIntPtr i, j;
762 	MyHashObject* pHObject;
763 	ByteString *pDepName;
764 	ByteString *pFlagName;
765 	Prj* pPrj;
766 	ObjectWin *pStartWin, *pEndWin;
767 	maToolBox.HideItem(TID_SOLDEP_SELECT_WORKSPACE);
768 	maToolBox.HideItem(TID_SOLDEP_HIDE_INDEPENDEND);
769 	maToolBox.HideItem(TID_SOLDEP_FIND);
770 	maToolBox.ShowItem(TID_SOLDEP_BACK);
771 	maToolBox.Invalidate();
772 
773     //clean up
774     mpObjectPrjList->ClearAndDelete();
775     GetDepWin()->ClearConnectorList();
776     if (mpPrjIdMapper) delete mpPrjIdMapper;
777     mpPrjIdMapper = new SolIdMapper( 63997 ); //generate clean mapper
778     mnPrjWinCount = 0;
779 	mnPrjLastId = 0;
780 
781 	sal_uIntPtr nCount = mpStarWriter->Count();
782 	GetDepWin()->EnablePaint( sal_False );
783     Point aPnt = GetGraphWin()->GetPosPixel();
784     Size aSize = GetGraphWin()->GetSizePixel();
785 
786     GetGraphWin()->SetPosSizePixel( aPnt, aSize );         // Hier wird das Window gesetzt
787 
788 	sal_Bool bReturn = sal_False;
789 
790 	for ( i=0; i<nCount; i++ )
791 	{
792 // pPrj->GetProjectName() returns the name of
793 // the project e.g. svtools
794 		pPrj = mpStarWriter->GetObject(i);
795 		ByteString sPrjName = pPrj->GetProjectName();
796 		if ( sPrjName == rListName )
797 		{
798 			bReturn = sal_True;
799 
800 			mpPrj = mpStarWriter->GetObject(i);
801 			sal_uIntPtr nDirCount = mpPrj->Count();
802 			for ( j=0; j<nDirCount; j++ )
803 			{
804 				CommandData *pData = mpPrj->GetObject(j);
805 				fprintf( stdout, "\tProjectDir : %s\n",
806 						pData->GetLogFile().GetBuffer());
807 // pData->GetLogFile() contains internal project IDs
808 // e.g. st_mkout etc.
809 				if ( pData->GetLogFile() != "" )
810 				{
811 					ByteString sItem = pData->GetLogFile();
812 					nObjectId = AddPrjObject( sItem, sal_False);
813 // there may be faster ways......
814 					ObjectWin *pWin = ObjIdToPtr( mpObjectPrjList, nObjectId );
815 					pWin->SetViewMask( 0x0001 );
816 // pData->GetPath() contains internal project directories
817 // e.g. svtools/inc etc.
818                     ByteString sPath = pData->GetPath();
819 					pWin->SetTipText( sPath );
820 				}
821 			}
822 
823 // set connectors for dependencies here
824 			for ( j=0; j<nDirCount; j++ )
825 			{
826 				CommandData *pData = mpPrj->GetObject(j);
827 				SByteStringList *pDeps = pData->GetDependencies();
828 				if ( pDeps )
829 				{
830 					ByteString sFlagName = pData->GetLogFile();
831 					pFlagName = &sFlagName;
832 					//pHObject = mpPrjIdMapper->Find( (*pFlagName).GetToken( 0, '.'));//mpSolIdMapper see ReadSource()
833                     pHObject = mpPrjIdMapper->Find( sFlagName.GetToken( 0, '.'));
834                     if (pHObject)
835                     {
836 
837     					nObjectId = pHObject->GetId();
838 
839 	    				sal_uIntPtr nDepCount = pDeps->Count();
840 		    			for ( sal_uIntPtr k=0; k<nDepCount; k++ )
841 			    		{
842 				    		pDepName = pDeps->GetObject(k);
843 					    	pHObject = mpPrjIdMapper->Find( (*pDepName).GetToken( 0, '.'));
844 						    if (pHObject )
845     						{
846 	    						nHashedId = pHObject->GetId();
847 		    					pStartWin = ObjIdToPtr( mpObjectPrjList, nHashedId );
848 			    				pEndWin = ObjIdToPtr( mpObjectPrjList, nObjectId );
849 
850 				    			AddConnectorToObjects( pStartWin, pEndWin );
851 					    	}
852 						    else
853     						{
854 	    						String sMessage;
855 		    					sMessage += String::CreateFromAscii("can't find ");
856 			    				sMessage += String( *pDepName, RTL_TEXTENCODING_UTF8 );
857 				    			sMessage += String::CreateFromAscii(".\ndependency ignored");
858 					    		WarningBox aBox( GetDepWin(), WB_OK, sMessage);
859 						    	aBox.Execute();
860 						    }
861 					    }
862                     }
863 				}
864 
865 			}
866 
867 			break;
868 		}
869 	}
870 	ByteString sNullDir = "null";
871 	nObjectId = AddPrjObject( sNullDir, sal_False);
872 	ObjectWin *pWin = ObjIdToPtr( mpObjectPrjList, nObjectId );
873 	pWin->SetViewMask( 0x0001 );
874 	mpGraphPrjWin->EnablePaint( sal_True );
875     //debug
876 //    int test_l = GetStartPrj(mpPrjIdMapper, mpObjectPrjList);
877 //    ObjectWin *pTestWin = ObjIdToPtr( mpObjectPrjList, test_l );
878 	AutoArrange( mpPrjIdMapper, mpObjectPrjList, GetStartPrj(mpPrjIdMapper, mpObjectPrjList), 0, GetStartPrj(mpPrjIdMapper, mpObjectPrjList) );
879     mpGraphWin->Hide();
880     mpGraphPrjWin->Show();
881 	mpGraphPrjWin->Invalidate();
882 
883 	return bReturn;
884 }
885 
886 /*****************************************************************************/
CloseWindow()887 sal_uInt16 SolDep::CloseWindow()
888 /*****************************************************************************/
889 {
890 
891 	((SystemWindow*)mpProcessWin)->Close();
892 	return 0;
893 }
894 
895 /*****************************************************************************/
ShowHelp()896 void SolDep::ShowHelp()
897 /*****************************************************************************/
898 {
899 	SvFileStream aHelpFile( String::CreateFromAscii( "g:\\soldep.hlp" ), STREAM_READ );
900 	String aHelpText;
901 	ByteString aGetStr;
902 
903 	if ( aHelpFile.IsOpen() )
904 	{
905 		while ( aHelpFile.ReadLine( aGetStr ) )
906 		{
907 			aHelpText += String (aGetStr, RTL_TEXTENCODING_UTF8);
908 			aHelpText += String::CreateFromAscii("\n");
909 		}
910 	}
911 	else
912 		aHelpText = String::CreateFromAscii("No Helpfile found.");
913 
914 	SolHelpDlg aHelpDlg( mpBaseWin, DtSodResId( RID_SD_DIALOG_HELP ));
915 	aHelpDlg.maMLEHelp.SetText( aHelpText );
916 	aHelpDlg.maMLEHelp.SetReadOnly();
917 	aHelpDlg.maMLEHelp.EnableFocusSelectionHide( sal_True );
918 	aHelpDlg.Execute();
919 }
920 
921 /*****************************************************************************/
FindProject()922 sal_Bool SolDep::FindProject()
923 /*****************************************************************************/
924 {
925 	SolFindProjectDlg aFindProjectDlg( GetDepWin(), GetObjectList() );
926 	ObjectWin* pObjectWin = NULL;
927     mpObjectList->ResetSelectedObject();
928     if (IsHideMode())
929     {
930         GetDepWin()->Invalidate();
931     }
932 
933     mpFocusWin=NULL;
934 
935 	if ( aFindProjectDlg.Execute() == RET_OK ) {
936 		msProject = aFindProjectDlg.GetProject();
937 		//now we have a project string
938 
939         pObjectWin = mpObjectList->GetPtrByName( msProject );
940 		if (pObjectWin)
941 		{
942 			mpObjectList->ResetSelectedObject();
943 			MarkObjects( pObjectWin );
944 		}
945 		else
946 		{
947 			mpObjectList->ResetSelectedObject();
948 			for ( sal_uInt16 i=0; i<mpObjectList->Count(); i++ )
949 			{
950 			   ObjectWin* pObjectWin = mpObjectList->GetObject( i );
951 			   if ( !pObjectWin->IsTop() )
952 					pObjectWin->SetViewMask(sal_False);
953 			}
954 		}
955 	}
956 	return sal_False;
957 }
958 
MarkObjects(ObjectWin * pObjectWin)959 sal_Bool SolDep::MarkObjects( ObjectWin* pObjectWin )
960 {
961     if (pObjectWin)
962     {
963         if (!(pObjectWin->IsNullObject()))
964         {
965             pObjectWin->SetMarkMode( MARKMODE_SELECTED );
966 	  	    pObjectWin->MarkNeeded();
967 	        pObjectWin->MarkDepending();
968             if (IsHideMode())
969             {
970                 GetDepWin()->Invalidate();
971             }
972         } else
973         {
974             fprintf(stdout,"null\n");
975         }
976     }
977     return sal_True;
978 }
979 
Resize()980 void SolDep::Resize()
981 {
982 //funzt! mu?aber von der applikation aufgerufen werden.
983     Point aOutPos = Point( 0, 0 );
984 	Size aOutSize = mpProcessWin->GetOutputSizePixel();
985 		// calculate output size
986     sal_uIntPtr nTaskHeight = maToolBox.CalcWindowSizePixel().Height();
987     sal_uIntPtr nTaskWidth  = maToolBox.CalcWindowSizePixel().Width();
988 	Size aSize( aOutSize.Width(), nTaskHeight );
989 
990 //	sal_uIntPtr nMenuHeight = 0;
991     Point aGraphWinPos = Point(0,0);
992     Size  aGraphWinSize = Size(0,0);
993 
994 //wei?nicht wie:    nMenuHeight = aMenuBar.GetWindow()->GetSizePixel().Height(); //H�he des Menues
995 
996     //aInRect = pTBManager->Resize( Rectangle( aOutPos, aOutSize );
997     // Set Docking-Rectangle for ToolBar
998     Rectangle aInRect;
999 
1000     if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_TOP ))
1001     {
1002         // waagerechte Toolbar oben
1003         maToolBox.SetPosSizePixel( aOutPos, Size( aOutSize.Width(), maToolBox.CalcWindowSizePixel().Height()));
1004         if( maToolBox.IsVisible())
1005         {
1006             Point aOutPosTmp;
1007             Size aOutSizeTmp;
1008             aOutPosTmp = Point( aOutPos.X(), aOutPos.Y() + maToolBox.CalcWindowSizePixel().Height());
1009             aOutSizeTmp = Size( aOutSize.Width(), aOutSize.Height() - maToolBox.CalcWindowSizePixel().Height());
1010             aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1011             aGraphWinPos = Point( 0, nTaskHeight );
1012             aGraphWinSize = Size( aOutSize.Width(), aOutSize.Height() - nTaskHeight);
1013         }
1014     }
1015     if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_BOTTOM ))
1016     {
1017         // waagerechte Toolbar unten
1018         Point aTbPos  = Point( aOutPos.X(), aOutPos.Y() + aOutSize.Height() - maToolBox.CalcWindowSizePixel().Height());
1019         Size  aTbSize = Size( aOutSize.Width(), maToolBox.CalcWindowSizePixel().Height());
1020         maToolBox.SetPosSizePixel( aTbPos, aTbSize );
1021         if( maToolBox.IsVisible())
1022         {
1023             Point aOutPosTmp;
1024             Size aOutSizeTmp;
1025             aOutPosTmp = Point( aOutPos.X(), aOutPos.Y() + maToolBox.CalcWindowSizePixel().Height());
1026             aOutSizeTmp = Size( aOutSize.Width(), aOutSize.Height() - maToolBox.CalcWindowSizePixel().Height());
1027             aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1028             aGraphWinPos = Point( 0, 0 );
1029             aGraphWinSize = Size( aOutSize.Width(), aOutSize.Height() - nTaskHeight);
1030         }
1031     }
1032     if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_LEFT ))
1033     {
1034         // senkrechte ToolBar links
1035         maToolBox.SetPosSizePixel( aOutPos, Size( maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height()));
1036         if( maToolBox.IsVisible())
1037         {
1038             Point aOutPosTmp;
1039             Size aOutSizeTmp;
1040             aOutPosTmp = Point( aOutPos.X() + maToolBox.CalcWindowSizePixel().Width(), aOutPos.Y());
1041             aOutSizeTmp = Size( aOutSize.Width()- maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height());
1042             aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1043             aGraphWinPos = Point( nTaskWidth, 0 );
1044             aGraphWinSize = Size( aOutSize.Width() - nTaskWidth, aOutSize.Height());
1045         }
1046     }
1047     if (( !maToolBox.IsFloatingMode() ) && ( maToolBox.GetAlign() == WINDOWALIGN_RIGHT ))
1048     {
1049         // senkrechte ToolBar rechts
1050         Point aTbPos = Point( aOutPos.X() + aOutSize.Width() - maToolBox.CalcWindowSizePixel().Width(), aOutPos.Y());
1051         Size  aTbSize= Size( maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height());
1052         maToolBox.SetPosSizePixel( aTbPos, aTbSize);
1053         if( maToolBox.IsVisible())
1054         {
1055             Point aOutPosTmp;
1056             Size aOutSizeTmp;
1057             aOutPosTmp = Point( aOutPos.X() + maToolBox.CalcWindowSizePixel().Width(), aOutPos.Y());
1058             aOutSizeTmp = Size( aOutSize.Width()- maToolBox.CalcWindowSizePixel().Width(), aOutSize.Height());
1059             aInRect = Rectangle( aOutPosTmp, aOutSizeTmp );
1060             aGraphWinPos = Point( 0, 0 );
1061             aGraphWinSize = Size( aOutSize.Width() - nTaskWidth, aOutSize.Height());
1062         }
1063     }
1064 
1065 	Rectangle rout = Rectangle( Point( 0,0 ), aOutSize ); //OutputToScreenPixel( aOutPos )
1066     Rectangle rin  = Rectangle( Point( 0,0 ),//OutputToScreenPixel( Point( aOutPos.X() - 20, aInRect.Top())
1067                 Size( aOutSize.Width(), aOutSize.Height()));
1068 /*
1069 	Rectangle rout = mpProcessWin->OutputToScreenPixel( aOutPos );
1070     Rectangle rin  = Rectangle( Point( 0,0 ),//OutputToScreenPixel( Point( aOutPos.X() - 20, aInRect.Top())
1071                 Size( aOutSize.Width(), aOutSize.Height()));
1072 */
1073     maToolBox.SetDockingRects( rout, rin );
1074 
1075     sal_Bool bFloating = maToolBox.IsFloatingMode();
1076 
1077     if ( bFloating )
1078     {
1079         GetGraphWin()->SetPosSizePixel(Point(0,0),aOutSize);
1080         //if (IsPrjView() && (mpPrjDep)) mpPrjDep->Resize();
1081         if (maToolBox.IsVisible()) maToolBox.Show();
1082     } else
1083     {
1084         GetGraphWin()->SetPosSizePixel( aGraphWinPos, aGraphWinSize );
1085     }
1086     if (maToolBox.IsVisible()) maToolBox.Show();
1087 }
1088 
AddConnectorPrjView(ObjectWin * pStartWin,ObjectWin * pEndWin)1089 sal_uInt16 SolDep::AddConnectorPrjView( ObjectWin* pStartWin, ObjectWin* pEndWin )
1090 {
1091 //	DBG_ASSERT( FALSE , "not yet" );
1092 	ByteString sEndName = pEndWin->GetBodyText();
1093 	ByteString sStartName = pStartWin->GetBodyText();
1094 	if ( sStartName != ByteString("null"))
1095 	{
1096 		CommandData* pEndData = mpPrj->GetDirectoryData( sEndName );
1097 		SByteStringList* pDeps = pEndData->GetDependencies();
1098 		if ( pDeps )
1099 			pDeps->PutString( &sStartName );
1100 		else
1101 		{
1102 			pDeps = new SByteStringList();
1103 			pEndData->SetDependencies( pDeps );
1104 			pDeps->PutString( &sStartName );
1105 			pEndData->GetDependencies();
1106 		}
1107 	}
1108 	return AddConnectorToObjects( pStartWin, pEndWin );
1109 }
1110 
RemoveConnectorPrjView(ObjectWin * pStartWin,ObjectWin * pEndWin)1111 sal_uInt16 SolDep::RemoveConnectorPrjView( ObjectWin* pStartWin, ObjectWin* pEndWin )
1112 {
1113 	ByteString sEndName = pEndWin->GetBodyText();
1114 	ByteString sStartName = pStartWin->GetBodyText();
1115 	CommandData* pEndData = mpPrj->GetDirectoryData( sEndName );
1116 	SByteStringList* pDeps = pEndData->GetDependencies();
1117 	if ( pDeps )
1118 	{
1119 		ByteString* pString;
1120 		sal_uIntPtr nDepsCount = pDeps->Count();
1121 		for ( sal_uIntPtr j = nDepsCount; j > 0; j-- )
1122 		{
1123 			pString = pDeps->GetObject( j - 1 );
1124 			if ( pString->GetToken( 0, '.') == sStartName )
1125 				pDeps->Remove( pString );
1126 		}
1127 	}
1128 	return RemoveConnectorFromObjects( pStartWin, pEndWin );
1129 }
1130 
AutoArrange(SolIdMapper * pIdMapper,ObjectList * pObjLst,sal_uIntPtr nTopId,sal_uIntPtr nBottmId,sal_uIntPtr aObjID)1131 sal_uInt16 SolDep::AutoArrange( SolIdMapper* pIdMapper, ObjectList* pObjLst, sal_uIntPtr nTopId, sal_uIntPtr nBottmId, sal_uIntPtr aObjID )
1132 {
1133     AutoArrangeDlgStart();
1134 	OptimizePos(pIdMapper, pObjLst, nTopId, nBottmId, aObjID );
1135     AutoArrangeDlgStop();
1136 	return 0;
1137 }
1138 
CalcPos(sal_uInt16 nSet,sal_uInt16 nIndex)1139 Point SolDep::CalcPos( sal_uInt16 nSet, sal_uInt16 nIndex )
1140 {
1141 	int nRowIndex = nIndex / DEPPER_MAX_WIDTH;
1142 	sal_uIntPtr nPosX = mnXOffset + nRowIndex % 3 * GetDefSize().Width() / 3 + ( nIndex - ( DEPPER_MAX_WIDTH * nRowIndex )) * (GetDefSize().Width() + OBJWIN_X_SPACING );
1143 
1144 	sal_uIntPtr nPosY = ( nSet + mnLevelOffset + nRowIndex ) * ( GetDefSize().Height() + OBJWIN_Y_SPACING ) + OBJWIN_Y_SPACING;
1145 	Point aPos( nPosX, nPosY );
1146 	return aPos;
1147 }
1148 
CalcXOffset(sal_uIntPtr nObjectsToFit)1149 sal_uIntPtr SolDep::CalcXOffset( sal_uIntPtr nObjectsToFit )
1150 {
1151 	long nDynXOffs;
1152 	long nXMiddle;
1153 	sal_uIntPtr nTrigger;
1154 
1155 	nXMiddle = GetDepWin()->PixelToLogic( GetDepWin()->GetSizePixel()).Width() / 2;
1156 	if ( nObjectsToFit > DEPPER_MAX_WIDTH )
1157 		nObjectsToFit = DEPPER_MAX_WIDTH - 1 + DEPPER_MAX_WIDTH % 2;
1158 	nTrigger = ( nObjectsToFit - 1 ) / 2;
1159 	nDynXOffs = ( GetDefSize().Width() + OBJWIN_X_SPACING ) * nTrigger;
1160 	sal_uIntPtr nXOffs = nXMiddle - nDynXOffs;
1161 
1162 	if ( sal_uIntPtr(nXMiddle - nDynXOffs) < mnMinDynXOffs )
1163 		mnMinDynXOffs = nXMiddle - nDynXOffs;
1164 
1165 	return nXOffs;
1166 
1167 }
1168 
CalcDistSum(ObjWinList * pObjList,DistType eDistType)1169 double SolDep::CalcDistSum( ObjWinList* pObjList, DistType eDistType )
1170 {
1171 	ObjectWin* pWin;
1172 	Connector* pCon;
1173 	sal_uIntPtr nObjCount = pObjList->Count();
1174 	double dRetVal = 0;
1175 	double dWinVal;
1176 	sal_uInt16 i, j;
1177 	sal_Bool bIsStart;
1178 
1179 	for ( i = 0; i < nObjCount; i++ )
1180 	{
1181 		pWin = pObjList->GetObject( i );
1182 
1183 		if ( pWin && pWin->IsVisible())
1184 		{
1185 			j = 0;
1186 			dWinVal = 0;
1187 			while ( (pCon = pWin->GetConnector( j )) )
1188 			{
1189 				if ( pCon->IsVisible()) {
1190 					bIsStart = pCon->IsStart( pWin );
1191 					if ( eDistType != BOTH )
1192 						if ( eDistType == TOPDOWN )
1193 						{
1194 							if ( bIsStart )
1195 							{
1196 								pCon->UpdatePosition( pWin, sal_False );
1197 								dWinVal += pCon->GetLen() * pWin->mnHeadDist;
1198 							}
1199 						}
1200 						else
1201 						{
1202 							if ( !bIsStart )
1203 							{
1204 								pCon->UpdatePosition( pWin, sal_False );
1205 								dWinVal += pCon->GetLen() * pWin->mnRootDist;
1206 							}
1207 
1208 						}
1209 					else
1210 					{
1211 						pCon->UpdatePosition( pWin, sal_False );
1212 						if ( !bIsStart )
1213 							dWinVal += pCon->GetLen() * ( pWin->mnHeadDist + 1 );
1214 						else
1215 							dWinVal += pCon->GetLen() * pWin->mnRootDist;
1216 					}
1217 				}
1218 				j++;
1219 			}
1220 //			if ( j != 0 )
1221 //				dWinVal /= j;
1222 			dRetVal += dWinVal;
1223 		}
1224 	}
1225 
1226 	return dRetVal;
1227 }
1228 
Impl_Traveller(ObjectWin * pWin,sal_uInt16 nDepth)1229 sal_uInt16 SolDep::Impl_Traveller( ObjectWin* pWin, sal_uInt16 nDepth )
1230 {
1231 	sal_uInt16 i = 0;
1232 	ObjectWin* pNewWin;
1233 	Connector* pCon;
1234 
1235 	nDepth++;
1236 
1237 	sal_uInt16 nMaxDepth = nDepth;
1238 
1239 	pWin->mbVisited = sal_True;
1240 	pWin->mnRootDist = Max ( nDepth, pWin-> mnRootDist );
1241 	if ( nDepth > DEPPER_MAX_DEPTH )
1242 	{
1243 		DBG_ASSERT( nDepth != DEPPER_MAX_DEPTH + 1, "Ringabh�ngigkeit!" );
1244 		nDepth++;
1245 		return DEP_ENDLES_RECURSION_FOUND;
1246 	}
1247 
1248 	while ( (pCon = pWin->GetConnector( i )) )
1249 	{
1250 		if ( pCon->IsStart( pWin )&& pCon->IsVisible() ) //removed: don't show null_project
1251 		{
1252 			pNewWin = pCon->GetOtherWin( pWin );
1253 			nMaxDepth = Max( Impl_Traveller( pNewWin, nDepth ), nMaxDepth );
1254 			if( nMaxDepth == DEP_ENDLES_RECURSION_FOUND )
1255 			{
1256 				mpTravellerList->Insert( pWin, LIST_APPEND );
1257 				return DEP_ENDLES_RECURSION_FOUND;
1258 			}
1259 		}
1260 		i++;
1261 	}
1262 	pWin->mnHeadDist = MAX( pWin->mnHeadDist, nMaxDepth - nDepth );
1263 	return nMaxDepth;
1264 }
1265 
1266 
Impl_PermuteMin(ObjWinList & rObjList,Point * pPosArray,ObjWinList & rResultList,double dMinDist,sal_uIntPtr nStart,sal_uIntPtr nSize,DistType eDistType)1267 double SolDep::Impl_PermuteMin( ObjWinList& rObjList, Point* pPosArray, ObjWinList& rResultList, double dMinDist, sal_uIntPtr nStart, sal_uIntPtr nSize, DistType eDistType )
1268 {
1269 
1270 	sal_uIntPtr i, j, l;
1271 	sal_uIntPtr nEnd = nStart + nSize;
1272 	ObjectWin* pSwapWin;
1273 	sal_uIntPtr nLevelObjCount = rObjList.Count();
1274 
1275 //dont use full recusion for more than 6 objects
1276 	if ( nLevelObjCount > 6 )
1277 	{
1278 		srand(( unsigned ) time( NULL ));
1279 
1280 		sal_uIntPtr nIdx1, nIdx2;
1281 		for ( i = 0; i < 101; i++ )
1282 		{
1283             UpdateSubProgrssBar(i);
1284 			for ( j = 0; j < 100; j++ )
1285 			{
1286 				nIdx1 = (sal_uIntPtr) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1287 				while ( rObjList.GetObject( nIdx1 ) == NULL )
1288 					nIdx1 = (sal_uIntPtr) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1289 				nIdx2 = (sal_uIntPtr) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1290 				while ( nIdx1 == nIdx2 || nIdx2 == nLevelObjCount )
1291 					nIdx2 = (sal_uIntPtr) ( double( rand() ) / RAND_MAX * nLevelObjCount );
1292 
1293 				pSwapWin = rObjList.GetObject( nIdx1 );
1294 				if ( pSwapWin )
1295 					pSwapWin->SetCalcPosPixel( pPosArray[ nIdx2 ] );
1296 				pSwapWin = rObjList.Replace( pSwapWin, nIdx2 );
1297 				if ( pSwapWin )
1298 					pSwapWin->SetCalcPosPixel( pPosArray[ nIdx1 ] );
1299 				rObjList.Replace( pSwapWin, nIdx1 );
1300 
1301 				double dCurDist = CalcDistSum( &rObjList, eDistType );
1302 
1303 				if ( dCurDist < dMinDist )
1304 				{
1305 					dMinDist = dCurDist;
1306 					rResultList.Clear();
1307 					for ( l = 0; l < nLevelObjCount; l++ )
1308 					{
1309 						pSwapWin = rObjList.GetObject( l );
1310 						rResultList.Insert( pSwapWin, LIST_APPEND);
1311 					}
1312 				}
1313 //				if ( dCurDist > dMinDist * 1.5 )
1314 				if ( dCurDist > dMinDist * 15 )
1315 				{
1316 					pSwapWin = rObjList.GetObject( nIdx1 );
1317 					if ( pSwapWin )
1318 						pSwapWin->SetCalcPosPixel( pPosArray[ nIdx2 ] );
1319 					pSwapWin = rObjList.Replace( pSwapWin, nIdx2 );
1320 					if ( pSwapWin )
1321 						pSwapWin->SetCalcPosPixel( pPosArray[ nIdx1 ] );
1322 					rObjList.Replace( pSwapWin, nIdx1 );
1323 				}
1324 			}
1325 		}
1326 	}
1327 	else
1328 	{
1329 		for ( i = nStart ; i < nEnd; i++)
1330 		{
1331 			if ( nSize > 1 )
1332 			{
1333 				pSwapWin = rObjList.GetObject( i );
1334 				pSwapWin = rObjList.Replace( pSwapWin, nStart );
1335 				rObjList.Replace( pSwapWin, i );
1336                 double dPermuteDist = Impl_PermuteMin( rObjList, pPosArray, rResultList, dMinDist, nStart + 1, nSize - 1, eDistType );
1337 				dMinDist = MIN( dMinDist, dPermuteDist);
1338 				pSwapWin = rObjList.GetObject( i );
1339 				pSwapWin = rObjList.Replace( pSwapWin, nStart );
1340 				rObjList.Replace( pSwapWin, i );
1341 
1342 			}
1343 			else
1344 			{
1345 				for ( l = 0; l < nLevelObjCount; l++ )
1346 				{
1347 					pSwapWin = rObjList.GetObject( l );
1348 					if ( pSwapWin )
1349 						pSwapWin->SetCalcPosPixel( pPosArray[ l ] );
1350 				}
1351 
1352 				double dCurDist = CalcDistSum( &rObjList, eDistType );
1353 
1354 				if ( dCurDist < dMinDist )
1355 				{
1356 					dMinDist = dCurDist;
1357 					rResultList.Clear();
1358 					for ( l = 0; l < nLevelObjCount; l++ )
1359 					{
1360 						pSwapWin = rObjList.GetObject( l );
1361 						rResultList.Insert( pSwapWin, LIST_APPEND);
1362 					}
1363 				}
1364 
1365 			}
1366 		}
1367 	}
1368 
1369 	return dMinDist;
1370 }
1371 
1372 
OptimizePos(SolIdMapper * pIdMapper,ObjectList * pObjLst,sal_uIntPtr nTopId,sal_uIntPtr nBottmId,sal_uIntPtr aObjID)1373 sal_uInt16 SolDep::OptimizePos(SolIdMapper* pIdMapper, ObjectList* pObjLst, sal_uIntPtr nTopId, sal_uIntPtr nBottmId, sal_uIntPtr aObjID )
1374 {
1375 	ObjWinList aWorkList;
1376 	ObjectWin* pWin;
1377 	Connector* pCon;
1378 	sal_uInt16 nRootDist = (sal_uInt16) -1;
1379 	sal_uInt16 i, j, k, l, nRetVal;
1380 	sal_uInt16 LevelUse[ DEPPER_MAX_DEPTH ];
1381 	sal_uInt16 LevelSecUse[ DEPPER_MAX_DEPTH ];
1382 	ObjWinList* LevelList[ DEPPER_MAX_DEPTH ];
1383 	ObjWinList* LevelSecList[ DEPPER_MAX_DEPTH ];
1384 	Point aPosArray[ DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH ];
1385 
1386 	mnMinDynXOffs = 0xffff;
1387 
1388 	for ( i = 0; i < DEPPER_MAX_DEPTH; i++ )
1389 	{
1390 		LevelUse[ i ] = 0;
1391 		LevelList[ i ] = NULL;
1392 		LevelSecUse[ i ] = 0;
1393 		LevelSecList[ i ] = NULL;
1394 	}
1395 
1396     GetDepWin()->EnablePaint( sal_False );
1397 
1398 	sal_uIntPtr nObjCount = pObjLst->Count();
1399 	for ( i = 0; i < nObjCount; i++ )
1400 	{
1401 		pWin = pObjLst->GetObject( i );
1402 		if ( pWin->IsVisible()) {
1403 			pWin->mbVisited = sal_False;
1404 			pWin->mnHeadDist = 0;
1405 			pWin->mnRootDist = 0;
1406 
1407 			// find initial objects which need to be connected with
1408 			// root object
1409 			j = 0;
1410 			sal_uInt16 nStartCount = 0;
1411 			sal_uInt16 nEndCount = 0;
1412 			while ( (pCon = pWin->GetConnector( j )) )
1413 			{
1414 				if ( pCon->IsVisible()) {                   //null_project
1415 					if( pCon->IsStart( pWin ))
1416 						nStartCount++;
1417 					else
1418 					{
1419 						nEndCount = 1;
1420 						break;
1421 					}
1422 				}
1423 				j++;
1424 			}
1425 
1426 			if ( nStartCount > 0 && nEndCount == 0 )
1427 				if ( nTopId != pWin->GetId())
1428 					AddConnectorToObjects( pObjLst, nTopId, pWin->GetId());
1429 
1430 		}
1431 	}
1432 
1433 	pWin = ObjIdToPtr( pObjLst, nTopId );
1434 
1435 	if ( mpTravellerList )
1436 	{
1437 		mpTravellerList->Clear();
1438 		delete mpTravellerList;
1439 	}
1440 	mpTravellerList = new ObjWinList();
1441 	// set root and top distance
1442 	nRetVal = Impl_Traveller( pWin, nRootDist );
1443 
1444 	DBG_ASSERT( nRetVal < DEPPER_MAX_DEPTH , "zu tief" );
1445 	if ( nRetVal == DEP_ENDLES_RECURSION_FOUND )
1446 	{
1447         WriteToErrorFile();
1448 		return nRetVal;
1449 	}
1450 
1451 	sal_uIntPtr nUnvisited = 0;
1452 	sal_uIntPtr nUnvisYOffs = 0;
1453 
1454 	// seperate mainstream, secondary and unconnected
1455 	for ( i = 0; i < nObjCount; i++ )
1456 	{
1457 		pWin = pObjLst->GetObject( i );
1458 		if ( pWin->IsVisible()) {
1459 			if (( pWin->mnHeadDist + pWin->mnRootDist ) == nRetVal )
1460 			{
1461 				if ( !LevelList[ pWin->mnHeadDist ] )
1462 						LevelList[ pWin->mnHeadDist ] = new ObjWinList;
1463     			LevelList[ pWin->mnHeadDist ]->Insert( pWin );
1464 				LevelUse[ pWin->mnHeadDist ]++;
1465 			}
1466 			else
1467 				if ( pWin->mbVisited )
1468 				{
1469 					if ( !LevelSecList[ nRetVal - pWin->mnRootDist ] )
1470 						LevelSecList[ nRetVal - pWin->mnRootDist ] = new ObjWinList;
1471 					LevelSecList[ nRetVal - pWin->mnRootDist ]->Insert( pWin );
1472 					LevelSecUse[ nRetVal - pWin->mnRootDist ]++;
1473 				}
1474 				else
1475 				{
1476 	//				need to be arranged more intelligent...
1477 					Point aPos( 5, nUnvisYOffs );
1478 					pWin->SetCalcPosPixel( aPos );
1479 
1480 					Point aTmpPos = pWin->GetCalcPosPixel();
1481 					pWin->SetPosPixel( mpBaseWin->LogicToPixel( aTmpPos ));
1482 
1483 					nUnvisYOffs += pWin->PixelToLogic( pWin->GetSizePixel()).Height();
1484 					nUnvisited++;
1485 				}
1486 		}
1487 	}
1488 
1489 	mnLevelOffset = 0;
1490 
1491 	sal_uInt16 nScaleVal;
1492 
1493 	if ( nRetVal == 0 )
1494 		nScaleVal = 1;
1495 	else
1496 		nScaleVal = nRetVal;
1497 
1498 	i = 0;
1499 
1500 	sal_uInt16 nStep = 0;
1501 
1502 	while ( LevelList[ i ] )
1503 	{
1504         UpdateMainProgressBar(i, nScaleVal, nStep);
1505 		DBG_ASSERT( LevelUse[ i ] == LevelList[ i ]->Count() , "level index im a..." );
1506 		ObjectWin* pSwapWin;
1507 		sal_uIntPtr nLevelObjCount = LevelList[ i ]->Count();
1508 
1509 		if ( nLevelObjCount % 2 == 0 )
1510 		{
1511 			LevelList[ i ]->Insert( NULL, LIST_APPEND );
1512 			nLevelObjCount++;
1513 //			LevelUse bleibt orginal...
1514 //			LevelUse[ i ]++;
1515 		}
1516 
1517 // catch too big lists
1518 		DBG_ASSERT( nLevelObjCount < DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH , "graph zu breit! dat geiht nich gut. breaking" );
1519 		if ( nLevelObjCount >= DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH )
1520 		{
1521 			WarningBox aWBox( mpBaseWin, WB_OK, String::CreateFromAscii("graph zu breit! dat geiht nich gut. breaking"));
1522 			aWBox.Execute();
1523 			break;
1524 		}
1525 		mnXOffset = CalcXOffset( nLevelObjCount );
1526 		aWorkList.Clear();
1527 
1528 		// initial positioning for mainstream
1529 		for ( j = 0; j < nLevelObjCount; j++ )
1530 		{
1531 			pSwapWin = LevelList[ i ]->GetObject( j );
1532 			aWorkList.Insert( pSwapWin, LIST_APPEND);
1533 			Point aPos = CalcPos( i, j );
1534 			aPosArray[ j ] = aPos;
1535 			if ( pSwapWin )
1536 				pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1537 		}
1538 
1539 		double dMinDist = CalcDistSum( LevelList[ i ] );
1540 
1541 		// optimize mainstream order and return best matching list in "aWorkList"
1542 		dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelObjCount ));
1543 
1544 		// set optimized positions - may still be wrong from later tries
1545 		for ( j = 0; j < nLevelObjCount; j++ )
1546 		{
1547 			pSwapWin = aWorkList.GetObject( j );
1548 			if ( pSwapWin )
1549 				pSwapWin->SetCalcPosPixel(  aPosArray[ j ] );
1550 		}
1551 
1552 		if ( LevelSecList[ i ] != NULL )
1553 		{
1554 			sal_uIntPtr nLevelSecObjCount = LevelSecList[ i ]->Count();
1555 			// expand list for better positioning
1556 			while ( nLevelSecObjCount + LevelUse[ i ] < DEPPER_MAX_WIDTH - 1 )
1557 			{
1558 				LevelSecList[ i ]->Insert( NULL, LIST_APPEND );
1559 				nLevelSecObjCount++;
1560 			}
1561 			if ( ( nLevelSecObjCount + LevelUse[ i ])% 2 == 0 )
1562 			{
1563 				LevelSecList[ i ]->Insert( NULL, LIST_APPEND );
1564 				nLevelSecObjCount++;
1565 			}
1566 
1567 			DBG_ASSERT( nLevelSecObjCount < DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH , "graph zu breit! dat geiht nich gut. breaking" );
1568 			if ( nLevelObjCount >= DEPPER_MAX_LEVEL_WIDTH * DEPPER_MAX_WIDTH )
1569 			{
1570 				WarningBox aWBox( mpBaseWin, WB_OK, String::CreateFromAscii("graph zu breit! dat geiht nich gut. breaking"));
1571 				aWBox.Execute();
1572 				break;
1573 			}
1574 			mnXOffset = CalcXOffset( LevelUse[ i ] + nLevelSecObjCount );
1575 			aWorkList.Clear();
1576 
1577 			l = 0;
1578 			sal_Bool bUsedPos;
1579 
1580 			// find free positions for secondary objects
1581 			for ( j = 0; j < ( LevelUse[ i ] + nLevelSecObjCount ) ; j++ )
1582 			{
1583 				Point aPos = CalcPos( i, j );
1584 				bUsedPos = sal_False;
1585 				// is already occupied?
1586 				for ( k = 0; k < nLevelObjCount; k++ )
1587 				{
1588 					if ( LevelList[ i ]->GetObject( k ) )
1589 						if ( aPos == LevelList[ i ]->GetObject( k )->GetCalcPosPixel() )
1590 							bUsedPos = sal_True;
1591 				}
1592 				// if its free, add to pool
1593 				if ( !bUsedPos )
1594 				{
1595 					aPosArray[ l ] = aPos;
1596 					l++;
1597 				}
1598 			}
1599 
1600 			// initial positioning for secodaries
1601 			for ( j = 0 ; j < nLevelSecObjCount ; j++ )
1602 			{
1603 				pSwapWin = LevelSecList[ i ]->GetObject( j );
1604 				aWorkList.Insert( pSwapWin, LIST_APPEND);
1605 				if ( pSwapWin )
1606 					pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1607 			}
1608 			dMinDist = CalcDistSum( LevelSecList[ i ] );
1609 
1610 			dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelSecList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelSecObjCount ));
1611 
1612 			// set optimized positions - may still be wrong from later tries
1613 			for ( j = 0; j < nLevelSecObjCount; j++ )
1614 			{
1615 				pSwapWin = aWorkList.GetObject( j );
1616 				if ( pSwapWin )
1617 					pSwapWin->SetCalcPosPixel(  aPosArray[ j ] );
1618 			}
1619 			if ( LevelUse[ i ] + LevelSecUse[ i ] > DEPPER_MAX_WIDTH )
1620 				mnLevelOffset++;
1621 		}
1622 		if ( LevelUse[ i ] + LevelSecUse[ i ] > DEPPER_MAX_WIDTH )
1623 			mnLevelOffset+= ( LevelUse[ i ] + LevelSecUse[ i ] ) / DEPPER_MAX_WIDTH ;
1624 		i++;
1625 	}
1626 
1627 	mnMinDynXOffs = 0xffff;
1628 
1629 // and back again...
1630 	// get better results form already preoptimized upper and lower rows
1631 
1632 	do
1633 	{
1634 		i--;
1635         UpdateMainProgressBar(i, nScaleVal, nStep, sal_True); // sal_True ~ counting down
1636 		if ( LevelUse[ i ] + LevelSecUse[ i ] > DEPPER_MAX_WIDTH )
1637 			mnLevelOffset-= ( LevelUse[ i ] + LevelSecUse[ i ] ) / DEPPER_MAX_WIDTH ;
1638 		ObjectWin* pSwapWin;
1639 		sal_uIntPtr nLevelObjCount = LevelList[ i ]->Count();
1640 		mnXOffset = CalcXOffset( nLevelObjCount );
1641 		aWorkList.Clear();
1642 
1643 		for ( j = 0; j < nLevelObjCount; j++ )
1644 		{
1645 			pSwapWin = LevelList[ i ]->GetObject( j );
1646 			aWorkList.Insert( pSwapWin, LIST_APPEND);
1647 			Point aPos = CalcPos( i, j );
1648 			aPosArray[ j ] = aPos;
1649 //no need to do this stuff....... 	?????
1650 			if ( pSwapWin )
1651 				pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1652 		}
1653 
1654 		double dMinDist = CalcDistSum( LevelList[ i ], BOTH );
1655 
1656 		dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelObjCount, BOTH ));
1657 // wrong position for remaping - keep old positions for comparing
1658 		for ( j = 0; j < nLevelObjCount; j++ )
1659 		{
1660 			pSwapWin = aWorkList.GetObject( j );
1661 			if ( pSwapWin )
1662 //				pSwapWin->SetCalcPosPixel( mpBaseWin->LogicToPixel( aPosArray[ j ] ));
1663 				pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1664 		}
1665 
1666 		if ( LevelSecList[ i ] != NULL )
1667 		{
1668 			sal_uIntPtr nLevelSecObjCount = LevelSecList[ i ]->Count();
1669 			mnXOffset = CalcXOffset( LevelUse[ i ] + nLevelSecObjCount );
1670 			aWorkList.Clear();
1671 
1672 			l = 0;
1673 			sal_Bool bUsedPos;
1674 
1675 			for ( j = 0; j < ( LevelUse[ i ] + nLevelSecObjCount ) ; j++ )
1676 			{
1677 				Point aPos = CalcPos( i, j );
1678 				bUsedPos = sal_False;
1679 // could be faster
1680 				for ( k = 0; k < nLevelObjCount; k++ )
1681 				{
1682 					if ( LevelList[ i ]->GetObject( k ) )
1683 						if ( aPos == LevelList[ i ]->GetObject( k )->GetCalcPosPixel() )
1684 							bUsedPos = sal_True;
1685 				}
1686 				if ( !bUsedPos )
1687 				{
1688 					aPosArray[ l ] = aPos;
1689 					l++;
1690 				}
1691 			}
1692 
1693 			for ( j = 0 ; j < nLevelSecObjCount ; j++ )
1694 			{
1695 				pSwapWin = LevelSecList[ i ]->GetObject( j );
1696 				aWorkList.Insert( pSwapWin, LIST_APPEND);
1697 				if ( pSwapWin )
1698 					pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1699 			}
1700 			dMinDist = CalcDistSum( LevelSecList[ i ], BOTH );
1701 
1702 			dMinDist = MIN( dMinDist, Impl_PermuteMin( *(LevelSecList[ i ]), aPosArray, aWorkList, dMinDist, 0, nLevelSecObjCount, BOTH ));
1703 // wrong position for remaping - keep old positions for comparing
1704 			for ( j = 0; j < nLevelSecObjCount; j++ )
1705 			{
1706 				pSwapWin = aWorkList.GetObject( j );
1707 				if ( pSwapWin )
1708 					pSwapWin->SetCalcPosPixel( aPosArray[ j ] );
1709 			}
1710 		}
1711 //		i--;
1712 	} while ( i != 0 );
1713     SetMainProgressBar( 100 );
1714 
1715 	sal_uIntPtr nNewXSize = ( DEPPER_MAX_WIDTH + 1 )  * ( OBJWIN_X_SPACING + GetDefSize().Width() );
1716 
1717     //    sal_uIntPtr aObjID = GetStart(pIdMapper, pObjLst) //hier mu?man switchen GetStart/GetPrjStart oder so
1718 
1719     ObjectWin* pObjWin = ObjIdToPtr( pObjLst, aObjID);
1720 
1721 	sal_uIntPtr nNewYSize = pObjWin->GetCalcPosPixel().Y() + GetDefSize().Height() + 2 * OBJWIN_Y_SPACING;
1722 	if (( nUnvisYOffs + GetDefSize().Height()) > nNewYSize )
1723 		nNewYSize = nUnvisYOffs + GetDefSize().Height();
1724 
1725 	MapMode aMapMode = GetDepWin()->GetMapMode();
1726 	Size aTmpSize( (sal_uIntPtr) (double(nNewXSize) * double( aMapMode.GetScaleX())), (sal_uIntPtr) (double( nNewYSize) * double( aMapMode.GetScaleY())));
1727 
1728 	Size aNowSize( GetGraphWin()->GetSizePixel());
1729 
1730 	if ( GetDepWin()->LogicToPixel( aNowSize ).Width() > aTmpSize.Width() )
1731 		aTmpSize.Width() = GetDepWin()->LogicToPixel( aNowSize ).Width() ;
1732 
1733 	if ( GetDepWin()->LogicToPixel( aNowSize ).Height()  > aTmpSize.Height() )
1734 		aTmpSize.Height() = GetDepWin()->LogicToPixel( aNowSize ).Height() ;
1735 
1736 //	if ( nZoomed <= 0 )
1737 //	{
1738 //		mpBaseWin->SetSizePixel( aTmpSize );
1739 //		mpGraphWin->SetTotalSize( aTmpSize );
1740 //		mpGraphWin->EndScroll( 0, 0 );
1741 //	}
1742 
1743 // now remap all objects
1744 	sal_uIntPtr nAllObjCount = pObjLst->Count();
1745 	Point aTmpPos;
1746 	for ( j = 0; j < nAllObjCount; j++ )
1747 	{
1748 		pWin = pObjLst->GetObject( j );
1749 		if ( pWin->IsVisible()) {
1750 			aTmpPos = pWin->GetCalcPosPixel();
1751 			if ( pWin->mbVisited )
1752 			{
1753 // reserve space for unconnected
1754 				aTmpPos.X() -= mnMinDynXOffs;
1755 				aTmpPos.X() += GetDefSize().Width() + OBJWIN_X_SPACING;
1756 // center window
1757 				aTmpPos.X() += GetDefSize().Width() / 2;
1758 				aTmpPos.X() -= pWin->PixelToLogic( pWin->GetSizePixel()).Width() / 2 ;
1759 			}
1760 			pWin->SetPosPixel( GetDepWin()->LogicToPixel( aTmpPos ));
1761 		}
1762 	}
1763 	aWorkList.Clear();
1764 	GetDepWin()->EnablePaint( sal_True );
1765 	GetDepWin()->Invalidate();
1766 //LevelListen loeschen	                H? Welche Levellisten?
1767 
1768 //Update all Connectors
1769 // --> To be done: Don't call twice Object1-Connector-Object2
1770 	ObjectWin* pObject1;
1771 	for ( i = 0 ; i < nObjCount ; i++)
1772 	{
1773 	    pObject1 = pObjLst->GetObject( i );
1774 		if ( pObject1->IsVisible())
1775 			pObject1->UpdateConnectors();
1776 	};
1777 	return 0;
1778 }
1779 
WriteToErrorFile()1780 void SolDep::WriteToErrorFile()
1781 {
1782 //Needs some improvement
1783     ObjectWin* pWin;
1784     WarningBox aWBox( mpBaseWin, WB_OK, String::CreateFromAscii("graph too deep! dat geiht nich gut.\nlook at depper.err in your Tmp-directory\nfor list of objects"));
1785 	aWBox.Execute();
1786 	char *tmpdir = getenv("TMP");
1787 	char *errfilebasename = "depper.err";
1788 	char *ErrFileName = (char*) malloc( strlen( tmpdir ) + strlen( errfilebasename) + 3 );
1789 	*ErrFileName = '\0';
1790 	strcat( ErrFileName, tmpdir );
1791 	strcat( ErrFileName, "\\" );
1792 	strcat( ErrFileName, errfilebasename );
1793 	FILE* pErrFile = fopen( "depper.err", "w+" );
1794 	if ( pErrFile )
1795 	{
1796 		for ( sal_uInt16 i = 0; i < mpTravellerList->Count(); i++ )
1797 		{
1798 			pWin = mpTravellerList->GetObject( i );
1799 			fprintf( pErrFile, " %s -> \n", (pWin->GetBodyText()).GetBuffer());
1800 		}
1801 		fclose( pErrFile );
1802 	}
1803 }
1804