1*d9e04f7dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*d9e04f7dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*d9e04f7dSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*d9e04f7dSAndrew Rist * distributed with this work for additional information
6*d9e04f7dSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*d9e04f7dSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*d9e04f7dSAndrew Rist * "License"); you may not use this file except in compliance
9*d9e04f7dSAndrew Rist * with the License. You may obtain a copy of the License at
10*d9e04f7dSAndrew Rist *
11*d9e04f7dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*d9e04f7dSAndrew Rist *
13*d9e04f7dSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*d9e04f7dSAndrew Rist * software distributed under the License is distributed on an
15*d9e04f7dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d9e04f7dSAndrew Rist * KIND, either express or implied. See the License for the
17*d9e04f7dSAndrew Rist * specific language governing permissions and limitations
18*d9e04f7dSAndrew Rist * under the License.
19*d9e04f7dSAndrew Rist *
20*d9e04f7dSAndrew Rist *************************************************************/
21*d9e04f7dSAndrew Rist
22*d9e04f7dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir
25cdf0e10cSrcweir #include <stdio.h>
26cdf0e10cSrcweir #include <tools/stream.hxx>
27cdf0e10cSrcweir #include <tools/debug.hxx>
28cdf0e10cSrcweir #include <vcl/msgbox.hxx>
29cdf0e10cSrcweir #include <svtools/prgsbar.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <soldep/depper.hxx>
32cdf0e10cSrcweir #include <soldep/objwin.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include "math.h"
35cdf0e10cSrcweir #include "time.h"
36cdf0e10cSrcweir #include "stdlib.h"
37cdf0e10cSrcweir #include "dtsodcmp.hrc"
38cdf0e10cSrcweir
39cdf0e10cSrcweir #include <vcl/svapp.hxx>
40cdf0e10cSrcweir
41cdf0e10cSrcweir #define MIN(a,b) (a)<(b)?(a):(b)
42cdf0e10cSrcweir #define MAX(a,b) (a)>(b)?(a):(b)
43cdf0e10cSrcweir
44cdf0e10cSrcweir ByteString sDelimiterLine("#==========================================================================");
45cdf0e10cSrcweir
46cdf0e10cSrcweir
47cdf0e10cSrcweir
48cdf0e10cSrcweir
Depper(Window * pBaseWindow)49cdf0e10cSrcweir Depper::Depper( Window* pBaseWindow ):
50cdf0e10cSrcweir Window( pBaseWindow ),
51cdf0e10cSrcweir mbIsPrjView(sal_False),
52cdf0e10cSrcweir maDefPos( 50, 50 ),
53cdf0e10cSrcweir maDefSize( 60, 25 ),
54cdf0e10cSrcweir mnViewMask( 1 ),
55cdf0e10cSrcweir pSubBar( NULL ),
56cdf0e10cSrcweir pMainBar( NULL ),
57cdf0e10cSrcweir pSubText( NULL ),
58cdf0e10cSrcweir pMainText( NULL ),
59cdf0e10cSrcweir maArrangeDlg( pBaseWindow ),
60cdf0e10cSrcweir mpPrjIdMapper( NULL ),
61cdf0e10cSrcweir maToolBox( pBaseWindow, DtSodResId(TID_SOLDEP_MAIN) ),
62cdf0e10cSrcweir maTaskBarFrame( pBaseWindow, 0)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir maArrangeDlg.Hide();
65cdf0e10cSrcweir
66cdf0e10cSrcweir mpProcessWin = pBaseWindow;
67cdf0e10cSrcweir mpGraphWin = new GraphWin( mpProcessWin, this );
68cdf0e10cSrcweir mpGraphPrjWin = new GraphWin( mpProcessWin, this );
69cdf0e10cSrcweir //mpBaseWin paints into virtual OutputDevice
70cdf0e10cSrcweir mpBaseWin = new DepWin( mpGraphWin->GetBufferWindow(), WB_NOBORDER | WB_SIZEABLE | WB_AUTOSIZE );
71cdf0e10cSrcweir mpBasePrjWin = new DepWin( mpGraphPrjWin->GetBufferWindow(), WB_NOBORDER | WB_SIZEABLE | WB_AUTOSIZE );
72cdf0e10cSrcweir
73cdf0e10cSrcweir mpGraphWin->SetBackground( Wallpaper( Color( COL_RED )));
74cdf0e10cSrcweir mpGraphPrjWin->SetBackground( Wallpaper( Color( COL_BLUE )));
75cdf0e10cSrcweir mpGraphPrjWin->Hide();
76cdf0e10cSrcweir mpBaseWin->SetBackground( Wallpaper( Color( COL_WHITE )));
77cdf0e10cSrcweir mpBasePrjWin->SetBackground( Wallpaper( Color( COL_LIGHTGRAY )));
78cdf0e10cSrcweir /*
79cdf0e10cSrcweir mpGraphWin->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
80cdf0e10cSrcweir mpGraphPrjWin->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
81cdf0e10cSrcweir mpBaseWin->SetZOrder( NULL, WINDOW_ZORDER_FIRST );
82cdf0e10cSrcweir */
83cdf0e10cSrcweir mpGraphWin->EnableClipSiblings();
84cdf0e10cSrcweir mpGraphPrjWin->EnableClipSiblings();
85cdf0e10cSrcweir
86cdf0e10cSrcweir mpParentProcessWin = mpProcessWin->GetParent();
87cdf0e10cSrcweir mpBaseWin->Show();
88cdf0e10cSrcweir nZoomed = 0;
89cdf0e10cSrcweir
90cdf0e10cSrcweir mpBaseWin->SetPopupHdl( this );
91cdf0e10cSrcweir mpBasePrjWin->SetPopupHdl( this );
92cdf0e10cSrcweir
93cdf0e10cSrcweir mpObjectList = new ObjectList(); //ObjectList unbekannt
94cdf0e10cSrcweir mpObjectPrjList = new ObjectList();
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
~Depper()97cdf0e10cSrcweir Depper::~Depper()
98cdf0e10cSrcweir {
99cdf0e10cSrcweir // delete mpObjectList;
100cdf0e10cSrcweir delete mpBaseWin;
101cdf0e10cSrcweir delete mpGraphWin;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
TogglePrjViewStatus()104cdf0e10cSrcweir sal_Bool Depper::TogglePrjViewStatus()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir GetDepWin()->Hide(); //Hide old content window
107cdf0e10cSrcweir GetGraphWin()->Hide();
108cdf0e10cSrcweir mbIsPrjView = !mbIsPrjView; //switch now
109cdf0e10cSrcweir GetDepWin()->Invalidate();
110cdf0e10cSrcweir GetGraphWin()->Show();
111cdf0e10cSrcweir GetDepWin()->Show(); //Show new content window
112cdf0e10cSrcweir return mbIsPrjView;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir
HideObjectsAndConnections(ObjectList * pObjLst)115cdf0e10cSrcweir void Depper::HideObjectsAndConnections( ObjectList* pObjLst )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir for ( sal_uIntPtr i = 0; i < pObjLst->Count(); i ++ ) {
118cdf0e10cSrcweir ObjectWin *pWin = pObjLst->GetObject( i );
119cdf0e10cSrcweir pWin->Hide();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir mpGraphWin->Hide();
122cdf0e10cSrcweir mpBaseWin->Hide();
123cdf0e10cSrcweir mpGraphPrjWin->Show();
124cdf0e10cSrcweir mpBasePrjWin->Show();
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
ShowObjectsAndConnections(ObjectList * pObjLst)127cdf0e10cSrcweir void Depper::ShowObjectsAndConnections( ObjectList* pObjLst )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir for ( sal_uIntPtr i = 0; i < pObjLst->Count(); i ++ ) {
130cdf0e10cSrcweir ObjectWin *pWin = pObjLst->GetObject( i );
131cdf0e10cSrcweir pWin->Show();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir mpBasePrjWin->Hide();
134cdf0e10cSrcweir mpGraphPrjWin->Hide();
135cdf0e10cSrcweir mpGraphWin->Show();
136cdf0e10cSrcweir mpBaseWin->Show();
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir
RemoveAllObjects(ObjectList * pObjLst)140cdf0e10cSrcweir void Depper::RemoveAllObjects( ObjectList* pObjLst )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir sal_uIntPtr i;
143cdf0e10cSrcweir
144cdf0e10cSrcweir for ( i = pObjLst->Count(); i > 0; i-- )
145cdf0e10cSrcweir delete pObjLst->GetObject( i - 1 );
146cdf0e10cSrcweir pObjLst->Clear();
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
Save(const ByteString & rFileName)149cdf0e10cSrcweir sal_uInt16 Depper::Save( const ByteString& rFileName )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir DBG_ASSERT( sal_False , "you are dead!" );
152cdf0e10cSrcweir SvFileStream aOutFile( String( rFileName, RTL_TEXTENCODING_UTF8 ), STREAM_WRITE );
153cdf0e10cSrcweir depper_head dh;
154cdf0e10cSrcweir sal_uInt16 i;
155cdf0e10cSrcweir sal_uIntPtr nObjCount = mpObjectList->Count();
156cdf0e10cSrcweir
157cdf0e10cSrcweir ConnectorList* pConList = GetDepWin()->GetConnectorList();
158cdf0e10cSrcweir sal_uIntPtr nCnctrCount = pConList->Count();
159cdf0e10cSrcweir
160cdf0e10cSrcweir dh.nID = DEPPER_ID;
161cdf0e10cSrcweir dh.nObjectCount = nObjCount;
162cdf0e10cSrcweir dh.nCnctrCount = nCnctrCount;
163cdf0e10cSrcweir
164cdf0e10cSrcweir aOutFile.Write( &dh, sizeof( dh ));
165cdf0e10cSrcweir
166cdf0e10cSrcweir for ( i=0; i < nObjCount ; i++ )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir mpObjectList->GetObject( i )->Save( aOutFile );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
171cdf0e10cSrcweir for ( i=0; i < nCnctrCount ; i++ )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir pConList->GetObject( i )->Save( aOutFile );
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir return 0;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
179cdf0e10cSrcweir
WriteSource()180cdf0e10cSrcweir sal_uInt16 Depper::WriteSource()
181cdf0e10cSrcweir {
182cdf0e10cSrcweir DBG_ASSERT( sal_False , "overload it!" );
183cdf0e10cSrcweir return 0;
184cdf0e10cSrcweir };
185cdf0e10cSrcweir
ReadSource(sal_Bool bUpdater)186cdf0e10cSrcweir sal_uInt16 Depper::ReadSource( sal_Bool bUpdater )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir DBG_ASSERT( sal_False , "overload it!" );
189cdf0e10cSrcweir return 0;
190cdf0e10cSrcweir };
191cdf0e10cSrcweir
OpenSource()192cdf0e10cSrcweir sal_uInt16 Depper::OpenSource()
193cdf0e10cSrcweir {
194cdf0e10cSrcweir DBG_ASSERT( sal_False , "overload it!" );
195cdf0e10cSrcweir return 0;
196cdf0e10cSrcweir };
197cdf0e10cSrcweir
ObjIdToPtr(ObjectList * pObjLst,sal_uIntPtr nId)198cdf0e10cSrcweir ObjectWin* Depper::ObjIdToPtr( ObjectList* pObjLst, sal_uIntPtr nId )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir sal_uIntPtr nObjCount = pObjLst->Count();
201cdf0e10cSrcweir sal_uIntPtr i = 0;
202cdf0e10cSrcweir ObjectWin* pWin;
203cdf0e10cSrcweir sal_uIntPtr nWinId = 0;
204cdf0e10cSrcweir
205cdf0e10cSrcweir do
206cdf0e10cSrcweir {
207cdf0e10cSrcweir pWin = pObjLst->GetObject( i );
208cdf0e10cSrcweir nWinId = pWin->GetId();
209cdf0e10cSrcweir i++;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir while( i < nObjCount && pWin->GetId() != nId );
212cdf0e10cSrcweir if ( pWin->GetId() == nId )
213cdf0e10cSrcweir return pWin;
214cdf0e10cSrcweir else
215cdf0e10cSrcweir return NULL;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
SetMainProgressBar(sal_uInt16 i)218cdf0e10cSrcweir void Depper::SetMainProgressBar( sal_uInt16 i)
219cdf0e10cSrcweir {
220cdf0e10cSrcweir if ( pMainBar ) {
221cdf0e10cSrcweir pMainBar->SetValue( 100 );
222cdf0e10cSrcweir pMainBar->Update();
223cdf0e10cSrcweir }
224cdf0e10cSrcweir }
225cdf0e10cSrcweir
UpdateMainProgressBar(sal_uInt16 i,sal_uInt16 nScaleVal,sal_uInt16 & nStep,sal_Bool bCountingDown)226cdf0e10cSrcweir void Depper::UpdateMainProgressBar(sal_uInt16 i, sal_uInt16 nScaleVal, sal_uInt16 &nStep, sal_Bool bCountingDown )
227cdf0e10cSrcweir {
228cdf0e10cSrcweir sal_uIntPtr val = 0;
229cdf0e10cSrcweir if ( pMainBar ) {
230cdf0e10cSrcweir // val = i * 50 / nScaleVal + 1;
231cdf0e10cSrcweir val = bCountingDown ? 50 + ( nScaleVal - i ) * 50 / nScaleVal : i * 50 / nScaleVal;
232cdf0e10cSrcweir
233cdf0e10cSrcweir pMainBar->SetValue( val );
234cdf0e10cSrcweir pMainBar->Update();
235cdf0e10cSrcweir String sText( String::CreateFromAscii( "Optimize step " ));
236cdf0e10cSrcweir sText += String::CreateFromInt32( ++nStep );
237cdf0e10cSrcweir pSubText->SetText( sText );
238cdf0e10cSrcweir }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir
UpdateSubProgrssBar(sal_uIntPtr i)241cdf0e10cSrcweir void Depper::UpdateSubProgrssBar(sal_uIntPtr i)
242cdf0e10cSrcweir {
243cdf0e10cSrcweir if ( pSubBar )
244cdf0e10cSrcweir {
245cdf0e10cSrcweir pSubBar->SetValue( i );
246cdf0e10cSrcweir pSubBar->Update();
247cdf0e10cSrcweir GetpApp()->Reschedule();
248cdf0e10cSrcweir }
249cdf0e10cSrcweir }
250cdf0e10cSrcweir
251cdf0e10cSrcweir
AutoArrangeDlgStart()252cdf0e10cSrcweir sal_uInt16 Depper::AutoArrangeDlgStart()
253cdf0e10cSrcweir {
254cdf0e10cSrcweir pSubBar = maArrangeDlg.GetSubBar();
255cdf0e10cSrcweir pMainBar = maArrangeDlg.GetMainBar();
256cdf0e10cSrcweir pSubText = maArrangeDlg.GetSubText();
257cdf0e10cSrcweir pMainText = maArrangeDlg.GetMainText();
258cdf0e10cSrcweir pMainText->SetText( String::CreateFromAscii( "Overall status" ));
259cdf0e10cSrcweir maArrangeDlg.Show();
260cdf0e10cSrcweir GetDepWin()->Enable( sal_False );
261cdf0e10cSrcweir GetDepWin()->Hide();
262cdf0e10cSrcweir return 0;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir
AutoArrangeDlgStop()265cdf0e10cSrcweir sal_uInt16 Depper::AutoArrangeDlgStop()
266cdf0e10cSrcweir {
267cdf0e10cSrcweir maArrangeDlg.Hide();
268cdf0e10cSrcweir GetDepWin()->Enable( sal_True );
269cdf0e10cSrcweir GetDepWin()->Show();
270cdf0e10cSrcweir pSubBar = NULL;
271cdf0e10cSrcweir pMainBar = NULL;
272cdf0e10cSrcweir pSubText = NULL;
273cdf0e10cSrcweir pMainText = NULL;
274cdf0e10cSrcweir return 0;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir
277cdf0e10cSrcweir
278cdf0e10cSrcweir
Zoom(MapMode & rMapMode)279cdf0e10cSrcweir sal_uInt16 Depper::Zoom( MapMode& rMapMode )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir sal_uIntPtr i;
282cdf0e10cSrcweir ObjectWin* pWin;
283cdf0e10cSrcweir Point aPos;
284cdf0e10cSrcweir Size aSize;
285cdf0e10cSrcweir ObjectList* pObjList;
286cdf0e10cSrcweir pObjList = GetObjectList();
287cdf0e10cSrcweir // aSize = mpBaseWin->GetSizePixel();
288cdf0e10cSrcweir // mpGraphWin->SetTotalSize( aSize );
289cdf0e10cSrcweir // mpGraphWin->EndScroll( 0, 0 );
290cdf0e10cSrcweir
291cdf0e10cSrcweir for ( i = pObjList->Count(); i > 0; i-- )
292cdf0e10cSrcweir {
293cdf0e10cSrcweir pWin = pObjList->GetObject( i - 1 );
294cdf0e10cSrcweir aPos = pWin->PixelToLogic( pWin->GetPosPixel());
295cdf0e10cSrcweir aSize = pWin->PixelToLogic( pWin->GetSizePixel());
296cdf0e10cSrcweir pWin->SetMapMode( rMapMode );
297cdf0e10cSrcweir aPos = pWin->LogicToPixel( aPos );
298cdf0e10cSrcweir aSize = pWin->LogicToPixel( aSize );
299cdf0e10cSrcweir pWin->SetPosSizePixel( aPos, aSize );
300cdf0e10cSrcweir }
301cdf0e10cSrcweir GetDepWin()->Invalidate();
302cdf0e10cSrcweir return 0;
303cdf0e10cSrcweir }
304cdf0e10cSrcweir
AddObjectToList(DepWin * pParentWin,ObjectList * pObjLst,sal_uIntPtr & LastID,sal_uIntPtr & WinCount,ByteString & rBodyText,sal_Bool bInteract)305cdf0e10cSrcweir sal_uIntPtr Depper::AddObjectToList( DepWin* pParentWin, ObjectList* pObjLst, sal_uIntPtr &LastID, sal_uIntPtr &WinCount, ByteString& rBodyText, sal_Bool bInteract )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir Point aPos;
308cdf0e10cSrcweir Size aSize = GetDefSize();
309cdf0e10cSrcweir
310cdf0e10cSrcweir aPos = GetDepWin()->LogicToPixel( aPos );
311cdf0e10cSrcweir aSize = GetDepWin()->LogicToPixel( aSize );
312cdf0e10cSrcweir return AddObjectToList( pParentWin, pObjLst, LastID, WinCount, rBodyText, aPos, aSize );
313cdf0e10cSrcweir }
314cdf0e10cSrcweir
AddObjectToList(DepWin * pParentWin,ObjectList * pObjLst,sal_uIntPtr & LastID,sal_uIntPtr & WinCount,ByteString & rBodyText,Point & rPos,Size & rSize)315cdf0e10cSrcweir sal_uIntPtr Depper::AddObjectToList( DepWin* pParentWin, ObjectList* pObjLst, sal_uIntPtr &LastID, sal_uIntPtr &WinCount, ByteString& rBodyText, Point& rPos, Size& rSize )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir ObjectWin* pWin = new ObjectWin( pParentWin, WB_BORDER );
318cdf0e10cSrcweir //pWin->mpDepperDontuseme = this;
319cdf0e10cSrcweir pWin->SetGlobalViewMask(mnViewMask); // Set ViewMask for all ObjectWin and Connector objects
320cdf0e10cSrcweir
321cdf0e10cSrcweir Size aNewSize;
322cdf0e10cSrcweir aNewSize.Width() = pWin->GetTextWidth( String( rBodyText, RTL_TEXTENCODING_UTF8 ));
323cdf0e10cSrcweir aNewSize.Height() = pWin->GetTextHeight();
324cdf0e10cSrcweir if ( aNewSize.Width() > rSize.Width() - 8 )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir aNewSize.Width() = aNewSize.Width() + 8;
327cdf0e10cSrcweir aNewSize.Height() = rSize.Height();
328cdf0e10cSrcweir }
329cdf0e10cSrcweir else
330cdf0e10cSrcweir aNewSize = rSize;
331cdf0e10cSrcweir pWin->SetPosSizePixel( rPos,aNewSize);
332cdf0e10cSrcweir
333cdf0e10cSrcweir MapMode aMapMode = mpBaseWin->GetMapMode();
334cdf0e10cSrcweir pWin->SetMapMode( aMapMode );
335cdf0e10cSrcweir
336cdf0e10cSrcweir pObjLst->Insert( pWin, LIST_APPEND );
337cdf0e10cSrcweir pWin->SetId( LastID );
338cdf0e10cSrcweir LastID++;
339cdf0e10cSrcweir WinCount++;
340cdf0e10cSrcweir pWin->SetBodyText( rBodyText );
341cdf0e10cSrcweir // pWin->Show();
342cdf0e10cSrcweir return pWin->GetId();
343cdf0e10cSrcweir }
344cdf0e10cSrcweir
345cdf0e10cSrcweir /*void Depper::DrawOutput( OutputDevice* pDevice )
346cdf0e10cSrcweir {
347cdf0e10cSrcweir GetDepWin()->DrawOutput( pDevice );
348cdf0e10cSrcweir ObjectList* pObjList = GetObjectList();
349cdf0e10cSrcweir for ( sal_uInt16 i = pObjList->Count(); i > 0; i-- )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir ObjectWin* pWin = pObjList->GetObject( i - 1 );
352cdf0e10cSrcweir pWin->DrawOutput( pDevice );
353cdf0e10cSrcweir }
354cdf0e10cSrcweir }*/
355cdf0e10cSrcweir
RemoveObjectFromList(ObjectList * pObjLst,sal_uIntPtr & WinCount,sal_uInt16 nId,sal_Bool bDelete)356cdf0e10cSrcweir ObjectWin* Depper::RemoveObjectFromList( ObjectList* pObjLst, sal_uIntPtr &WinCount, sal_uInt16 nId, sal_Bool bDelete )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir ObjectWin* pWin = ObjIdToPtr( pObjLst, nId );
359cdf0e10cSrcweir
360cdf0e10cSrcweir if ( pWin )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir pObjLst->Remove( pWin );
363cdf0e10cSrcweir WinCount--;
364cdf0e10cSrcweir if( bDelete )
365cdf0e10cSrcweir delete pWin;
366cdf0e10cSrcweir return pWin;
367cdf0e10cSrcweir }
368cdf0e10cSrcweir else
369cdf0e10cSrcweir return NULL;
370cdf0e10cSrcweir }
AddConnectorToObjects(ObjectList * pObjLst,sal_uIntPtr nStartId,sal_uIntPtr nEndId)371cdf0e10cSrcweir sal_uInt16 Depper::AddConnectorToObjects( ObjectList* pObjLst, sal_uIntPtr nStartId, sal_uIntPtr nEndId )
372cdf0e10cSrcweir {
373cdf0e10cSrcweir ObjectWin* pStartWin = ObjIdToPtr( pObjLst, nStartId );
374cdf0e10cSrcweir
375cdf0e10cSrcweir if ( !pStartWin )
376cdf0e10cSrcweir return DEP_STARTID_NOT_FOUND;
377cdf0e10cSrcweir
378cdf0e10cSrcweir ObjectWin* pEndWin = ObjIdToPtr( pObjLst, nEndId );
379cdf0e10cSrcweir
380cdf0e10cSrcweir if ( !pEndWin )
381cdf0e10cSrcweir return DEP_STARTID_NOT_FOUND;
382cdf0e10cSrcweir
383cdf0e10cSrcweir return AddConnectorToObjects( pStartWin, pEndWin );
384cdf0e10cSrcweir }
385cdf0e10cSrcweir
RemoveConnectorFromObjects(ObjectList * pObjLst,sal_uIntPtr nStartId,sal_uIntPtr nEndId)386cdf0e10cSrcweir sal_uInt16 Depper::RemoveConnectorFromObjects( ObjectList* pObjLst, sal_uIntPtr nStartId, sal_uIntPtr nEndId )
387cdf0e10cSrcweir {
388cdf0e10cSrcweir // DBG_ASSERT( FALSE , "noch nicht" );
389cdf0e10cSrcweir ObjectWin* pStartWin = ObjIdToPtr( pObjLst, nStartId );
390cdf0e10cSrcweir
391cdf0e10cSrcweir if ( !pStartWin )
392cdf0e10cSrcweir return DEP_STARTID_NOT_FOUND;
393cdf0e10cSrcweir
394cdf0e10cSrcweir ObjectWin* pEndWin = ObjIdToPtr( pObjLst, nEndId );
395cdf0e10cSrcweir
396cdf0e10cSrcweir if ( !pEndWin )
397cdf0e10cSrcweir return DEP_STARTID_NOT_FOUND;
398cdf0e10cSrcweir
399cdf0e10cSrcweir return RemoveConnectorFromObjects( pStartWin, pEndWin );
400cdf0e10cSrcweir }
401cdf0e10cSrcweir
AddConnectorToObjects(ObjectWin * pStartWin,ObjectWin * pEndWin)402cdf0e10cSrcweir sal_uInt16 Depper::AddConnectorToObjects( ObjectWin* pStartWin, ObjectWin* pEndWin )
403cdf0e10cSrcweir {
404cdf0e10cSrcweir if ( pStartWin->ConnectionExistsInAnyDirection( pEndWin ))
405cdf0e10cSrcweir return 0;
406cdf0e10cSrcweir
407cdf0e10cSrcweir Connector* pCon = new Connector( GetDepWin(), WB_NOBORDER );
408cdf0e10cSrcweir // pCon->Initialize( pStartWin, pEndWin );
409cdf0e10cSrcweir if (pStartWin->IsNullObject()) //null_project
410cdf0e10cSrcweir pCon->Initialize( pStartWin, pEndWin, sal_False );
411cdf0e10cSrcweir else
412cdf0e10cSrcweir pCon->Initialize( pStartWin, pEndWin, sal_True );
413cdf0e10cSrcweir return 0;
414cdf0e10cSrcweir }
415cdf0e10cSrcweir
RemoveConnectorFromObjects(ObjectWin * pStartWin,ObjectWin * pEndWin)416cdf0e10cSrcweir sal_uInt16 Depper::RemoveConnectorFromObjects( ObjectWin* pStartWin, ObjectWin* pEndWin )
417cdf0e10cSrcweir {
418cdf0e10cSrcweir Connector* pCon = pStartWin->GetConnector( pStartWin->GetId(), pEndWin->GetId() );
419cdf0e10cSrcweir
420cdf0e10cSrcweir if ( !pCon )
421cdf0e10cSrcweir return DEP_CONNECTOR_NOT_FOUND;
422cdf0e10cSrcweir else
423cdf0e10cSrcweir {
424cdf0e10cSrcweir delete pCon;
425cdf0e10cSrcweir return DEP_OK;
426cdf0e10cSrcweir }
427cdf0e10cSrcweir }
428cdf0e10cSrcweir
HandleNewPrjDialog(ByteString & rBodyText)429cdf0e10cSrcweir sal_uIntPtr Depper::HandleNewPrjDialog( ByteString &rBodyText )
430cdf0e10cSrcweir {
431cdf0e10cSrcweir SolNewProjectDlg aNewProjectDlg( GetDepWin(), DtSodResId( RID_SD_DIALOG_NEWPROJECT ));
432cdf0e10cSrcweir if ( aNewProjectDlg.Execute() )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir rBodyText = ByteString( aNewProjectDlg.maEName.GetText(), RTL_TEXTENCODING_UTF8);
435cdf0e10cSrcweir //hashtable auf stand halten
436cdf0e10cSrcweir MyHashObject* pHObject;
437cdf0e10cSrcweir sal_uIntPtr nObjectId = AddObjectToList( mpBaseWin, mpObjectList, mnSolLastId, mnSolWinCount, rBodyText, sal_False );
438cdf0e10cSrcweir pHObject = new MyHashObject( nObjectId, ObjIdToPtr( mpObjectList, nObjectId ));
439cdf0e10cSrcweir mpSolIdMapper->Insert( rBodyText, pHObject );
440cdf0e10cSrcweir
441cdf0e10cSrcweir ByteString sTokenLine( aNewProjectDlg.maEShort.GetText(), RTL_TEXTENCODING_UTF8 );
442cdf0e10cSrcweir sTokenLine += '\t';
443cdf0e10cSrcweir sTokenLine += ByteString( aNewProjectDlg.maEName.GetText(), RTL_TEXTENCODING_UTF8 );
444cdf0e10cSrcweir sTokenLine += "\t:\t";
445cdf0e10cSrcweir
446cdf0e10cSrcweir ByteString sDeps = ByteString( aNewProjectDlg.maEDeps.GetText(), RTL_TEXTENCODING_UTF8 );
447cdf0e10cSrcweir
448cdf0e10cSrcweir if ( sDeps != "" )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir sal_uInt16 i;
451cdf0e10cSrcweir ByteString sDepName;
452cdf0e10cSrcweir sal_uInt16 nToken = sDeps.GetTokenCount(' ');
453cdf0e10cSrcweir for ( i = 0 ; i < nToken ; i++)
454cdf0e10cSrcweir {
455cdf0e10cSrcweir sDepName = sDeps.GetToken( i, ' ' );
456cdf0e10cSrcweir sTokenLine += sDepName;
457cdf0e10cSrcweir sTokenLine +='\t';
458cdf0e10cSrcweir }
459cdf0e10cSrcweir }
460cdf0e10cSrcweir sTokenLine +="NULL";
461cdf0e10cSrcweir
462cdf0e10cSrcweir mpStarWriter->InsertTokenLine( sTokenLine );
463cdf0e10cSrcweir mpStarWriter->InsertTokenLine( sDelimiterLine );
464cdf0e10cSrcweir
465cdf0e10cSrcweir if ( sDeps != "" )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir sal_uInt16 i;
468cdf0e10cSrcweir ByteString sDepName;
469cdf0e10cSrcweir sal_uIntPtr nObjectId_l, nHashedId;
470cdf0e10cSrcweir MyHashObject* pHObject_l;
471cdf0e10cSrcweir sal_uInt16 nToken = sDeps.GetTokenCount(' ');
472cdf0e10cSrcweir for ( i = 0 ; i < nToken ; i++)
473cdf0e10cSrcweir {
474cdf0e10cSrcweir sDepName = sDeps.GetToken( i, ' ' );
475cdf0e10cSrcweir
476cdf0e10cSrcweir pHObject_l = mpSolIdMapper->Find( sDepName );
477cdf0e10cSrcweir if ( !pHObject_l )
478cdf0e10cSrcweir {
479cdf0e10cSrcweir String sMessage;
480cdf0e10cSrcweir sMessage += String::CreateFromAscii("can't find ");
481cdf0e10cSrcweir sMessage += String( sDepName, RTL_TEXTENCODING_UTF8 );
482cdf0e10cSrcweir sMessage += String::CreateFromAscii(".\ndependency ignored");
483cdf0e10cSrcweir WarningBox aBox( GetDepWin(), WB_OK, sMessage);
484cdf0e10cSrcweir aBox.Execute();
485cdf0e10cSrcweir }
486cdf0e10cSrcweir else
487cdf0e10cSrcweir {
488cdf0e10cSrcweir nHashedId = pHObject_l->GetId();
489cdf0e10cSrcweir pHObject_l = mpSolIdMapper->Find( rBodyText );
490cdf0e10cSrcweir nObjectId_l = pHObject_l->GetId();
491cdf0e10cSrcweir AddConnectorToObjects( mpObjectList, nHashedId, nObjectId_l );
492cdf0e10cSrcweir }
493cdf0e10cSrcweir }
494cdf0e10cSrcweir }
495cdf0e10cSrcweir return nObjectId;
496cdf0e10cSrcweir }
497cdf0e10cSrcweir return 0;
498cdf0e10cSrcweir }
499cdf0e10cSrcweir
HandleNewDirectoryDialog(ByteString & rBodyText)500cdf0e10cSrcweir sal_uIntPtr Depper::HandleNewDirectoryDialog(ByteString &rBodyText)
501cdf0e10cSrcweir {
502cdf0e10cSrcweir SolNewDirectoryDlg aNewDirectoryDlg( GetDepWin(), DtSodResId( RID_SD_DIALOG_NEWDIRECTORY ));
503cdf0e10cSrcweir //todo: set defaults
504cdf0e10cSrcweir if ( aNewDirectoryDlg.Execute() )
505cdf0e10cSrcweir {
506cdf0e10cSrcweir rBodyText = ByteString( aNewDirectoryDlg.maEFlag.GetText(), RTL_TEXTENCODING_UTF8 );
507cdf0e10cSrcweir //hashtable auf stand halten
508cdf0e10cSrcweir MyHashObject* pHObject;
509cdf0e10cSrcweir sal_uIntPtr nObjectId = AddObjectToList( GetDepWin(), mpObjectPrjList, mnSolLastId, mnSolWinCount, rBodyText );
510cdf0e10cSrcweir pHObject = new MyHashObject( nObjectId, ObjIdToPtr( mpObjectPrjList, nObjectId ));
511cdf0e10cSrcweir mpPrjIdMapper->Insert( rBodyText, pHObject ); // mpPrjIdMapper
512cdf0e10cSrcweir
513cdf0e10cSrcweir String sTokenLine;
514cdf0e10cSrcweir sTokenLine = String( mpPrj->GetPreFix(), RTL_TEXTENCODING_UTF8 );
515cdf0e10cSrcweir sTokenLine += '\t';
516cdf0e10cSrcweir String sNameConvert = aNewDirectoryDlg.maEName.GetText();
517cdf0e10cSrcweir sNameConvert.SearchAndReplaceAll( '/', '\\' );
518cdf0e10cSrcweir if ( sNameConvert.GetToken( 0, 0x5c ) != String( mpPrj->GetProjectName(), RTL_TEXTENCODING_UTF8 ))
519cdf0e10cSrcweir {
520cdf0e10cSrcweir sTokenLine += String( mpPrj->GetProjectName(), RTL_TEXTENCODING_UTF8 );
521cdf0e10cSrcweir sTokenLine += String("\\", RTL_TEXTENCODING_UTF8 );
522cdf0e10cSrcweir sTokenLine += sNameConvert;
523cdf0e10cSrcweir }
524cdf0e10cSrcweir else
525cdf0e10cSrcweir sTokenLine += sNameConvert;
526cdf0e10cSrcweir sTokenLine += '\t';
527cdf0e10cSrcweir sTokenLine += aNewDirectoryDlg.maEAction.GetText();
528cdf0e10cSrcweir sTokenLine += String( "\t-\t", RTL_TEXTENCODING_UTF8 );
529cdf0e10cSrcweir sTokenLine += aNewDirectoryDlg.maEEnv.GetText();
530cdf0e10cSrcweir sTokenLine += '\t';
531cdf0e10cSrcweir sTokenLine += aNewDirectoryDlg.maEFlag.GetText();
532cdf0e10cSrcweir sTokenLine += '\t';
533cdf0e10cSrcweir
534cdf0e10cSrcweir sTokenLine += String( "NULL", RTL_TEXTENCODING_UTF8 );
535cdf0e10cSrcweir
536cdf0e10cSrcweir ByteString bsTokenLine = ByteString( sTokenLine, RTL_TEXTENCODING_UTF8 );
537cdf0e10cSrcweir mpStarWriter->InsertTokenLine( bsTokenLine );
538cdf0e10cSrcweir
539cdf0e10cSrcweir if ( aNewDirectoryDlg.maEDeps.GetText() != String( "", RTL_TEXTENCODING_UTF8 ))
540cdf0e10cSrcweir {
541cdf0e10cSrcweir sal_uInt16 i;
542cdf0e10cSrcweir ByteString sDeps = ByteString( aNewDirectoryDlg.maEDeps.GetText(), RTL_TEXTENCODING_UTF8 );
543cdf0e10cSrcweir ByteString sDepName;
544cdf0e10cSrcweir sal_uIntPtr nObjectId_l, nHashedId;
545cdf0e10cSrcweir MyHashObject* pHObject_l;
546cdf0e10cSrcweir sal_uInt16 nToken = sDeps.GetTokenCount(' ');
547cdf0e10cSrcweir for ( i = 0 ; i < nToken ; i++)
548cdf0e10cSrcweir {
549cdf0e10cSrcweir sDepName = sDeps.GetToken( i, ' ' );
550cdf0e10cSrcweir
551cdf0e10cSrcweir pHObject_l = mpPrjIdMapper->Find( sDepName ); // mpPrjIdMapper
552cdf0e10cSrcweir if ( !pHObject_l )
553cdf0e10cSrcweir {
554cdf0e10cSrcweir String sMessage;
555cdf0e10cSrcweir sMessage += String::CreateFromAscii("can't find ");
556cdf0e10cSrcweir sMessage += String( sDepName, RTL_TEXTENCODING_UTF8 );
557cdf0e10cSrcweir sMessage += String::CreateFromAscii(".\ndependency ignored");
558cdf0e10cSrcweir WarningBox aBox( mpBaseWin, WB_OK, sMessage);
559cdf0e10cSrcweir aBox.Execute();
560cdf0e10cSrcweir }
561cdf0e10cSrcweir else
562cdf0e10cSrcweir {
563cdf0e10cSrcweir sTokenLine += String( sDepName, RTL_TEXTENCODING_UTF8 );
564cdf0e10cSrcweir sTokenLine +='\t';
565cdf0e10cSrcweir nHashedId = pHObject_l->GetId();
566cdf0e10cSrcweir pHObject_l = mpPrjIdMapper->Find( rBodyText ); // mpPrjIdMapper
567cdf0e10cSrcweir nObjectId_l = pHObject_l->GetId();
568cdf0e10cSrcweir AddConnectorToObjects( mpObjectPrjList, nHashedId, nObjectId_l );
569cdf0e10cSrcweir }
570cdf0e10cSrcweir }
571cdf0e10cSrcweir }
572cdf0e10cSrcweir
573cdf0e10cSrcweir if ( mpPrj->Count() > 1 )
574cdf0e10cSrcweir {
575cdf0e10cSrcweir CommandData* pData = mpPrj->GetObject( mpPrj->Count() - 1 );
576cdf0e10cSrcweir pData = mpPrj->Replace( pData, mpPrj->Count() - 2 );
577cdf0e10cSrcweir mpPrj->Replace( pData, mpPrj->Count() - 1 );
578cdf0e10cSrcweir }
579cdf0e10cSrcweir
580cdf0e10cSrcweir return nObjectId;
581cdf0e10cSrcweir }
582cdf0e10cSrcweir return 0;
583cdf0e10cSrcweir }
584cdf0e10cSrcweir
585cdf0e10cSrcweir // Context-Menue
IMPL_LINK(Depper,PopupSelected,PopupMenu *,mpPopup)586cdf0e10cSrcweir IMPL_LINK( Depper, PopupSelected, PopupMenu*, mpPopup )
587cdf0e10cSrcweir {
588cdf0e10cSrcweir sal_uInt16 nItemId = mpPopup->GetCurItemId();
589cdf0e10cSrcweir
590cdf0e10cSrcweir switch( nItemId )
591cdf0e10cSrcweir {
592cdf0e10cSrcweir case DEPPOPUP_NEW :
593cdf0e10cSrcweir {
594cdf0e10cSrcweir ByteString sNewItem = ByteString("new");
595cdf0e10cSrcweir //AddObject( mpObjectList, sNewItem , sal_True );
596cdf0e10cSrcweir }
597cdf0e10cSrcweir break;
598cdf0e10cSrcweir case DEPPOPUP_AUTOARRANGE :
599cdf0e10cSrcweir //AutoArrange( mpObjectList, mpObjectList, GetStart(), 0 );
600cdf0e10cSrcweir break;
601cdf0e10cSrcweir case DEPPOPUP_LOAD :
602cdf0e10cSrcweir //Load( ByteString("test.dep"));
603cdf0e10cSrcweir break;
604cdf0e10cSrcweir case DEPPOPUP_SAVE :
605cdf0e10cSrcweir Save( ByteString("test.dep"));
606cdf0e10cSrcweir break;
607cdf0e10cSrcweir case DEPPOPUP_WRITE_SOURCE :
608cdf0e10cSrcweir WriteSource();
609cdf0e10cSrcweir break;
610cdf0e10cSrcweir case DEPPOPUP_READ_SOURCE :
611cdf0e10cSrcweir ReadSource(sal_True);
612cdf0e10cSrcweir break;
613cdf0e10cSrcweir case DEPPOPUP_OPEN_SOURCE :
614cdf0e10cSrcweir OpenSource();
615cdf0e10cSrcweir break;
616cdf0e10cSrcweir case DEPPOPUP_ZOOMIN :
617cdf0e10cSrcweir {
618cdf0e10cSrcweir // DBG_ASSERT( FALSE,"zoomin");
619cdf0e10cSrcweir MapMode aMapMode = GetDepWin()->GetMapMode();
620cdf0e10cSrcweir aMapMode.SetScaleX( aMapMode.GetScaleX() * Fraction( 1.25 ));
621cdf0e10cSrcweir aMapMode.SetScaleY( aMapMode.GetScaleY() * Fraction( 1.25 ));
622cdf0e10cSrcweir GetDepWin()->SetMapMode( aMapMode );
623cdf0e10cSrcweir
624cdf0e10cSrcweir if ( nZoomed < 1 )
625cdf0e10cSrcweir {
626cdf0e10cSrcweir Size aZoomInSize( GetDepWin()->GetSizePixel());
627cdf0e10cSrcweir aZoomInSize.Width() *= 1.25;
628cdf0e10cSrcweir aZoomInSize.Height() *= 1.25;
629cdf0e10cSrcweir GetDepWin()->SetSizePixel( aZoomInSize );
630cdf0e10cSrcweir }
631cdf0e10cSrcweir nZoomed--;
632cdf0e10cSrcweir
633cdf0e10cSrcweir Zoom( aMapMode );
634cdf0e10cSrcweir };
635cdf0e10cSrcweir break;
636cdf0e10cSrcweir case DEPPOPUP_ZOOMOUT :
637cdf0e10cSrcweir {
638cdf0e10cSrcweir // DBG_ASSERT( FALSE,"zoomout");
639cdf0e10cSrcweir MapMode aMapMode = GetDepWin()->GetMapMode();
640cdf0e10cSrcweir if ( aMapMode.GetScaleX() > Fraction( 0.25 ))
641cdf0e10cSrcweir {
642cdf0e10cSrcweir aMapMode.SetScaleX( aMapMode.GetScaleX() * Fraction( 0.8 ));
643cdf0e10cSrcweir aMapMode.SetScaleY( aMapMode.GetScaleY() * Fraction( 0.8 ));
644cdf0e10cSrcweir GetDepWin()->SetMapMode( aMapMode );
645cdf0e10cSrcweir
646cdf0e10cSrcweir if ( nZoomed < 0 )
647cdf0e10cSrcweir {
648cdf0e10cSrcweir Size aZoomOutSize( mpBaseWin->GetSizePixel());
649cdf0e10cSrcweir aZoomOutSize.Width() *= 0.8;
650cdf0e10cSrcweir aZoomOutSize.Height() *= 0.8;
651cdf0e10cSrcweir GetDepWin()->SetSizePixel( aZoomOutSize );
652cdf0e10cSrcweir }
653cdf0e10cSrcweir nZoomed++;
654cdf0e10cSrcweir
655cdf0e10cSrcweir Zoom( aMapMode );
656cdf0e10cSrcweir }
657cdf0e10cSrcweir };
658cdf0e10cSrcweir break;
659cdf0e10cSrcweir case DEPPOPUP_CLEAR :
660cdf0e10cSrcweir // DBG_ASSERT( FALSE,"clear");
661cdf0e10cSrcweir // RemoveAllObjects( mpObjectList );
662cdf0e10cSrcweir break;
663cdf0e10cSrcweir case DEPPOPUP_CLOSE :
664cdf0e10cSrcweir // DBG_ASSERT( FALSE,"close");
665cdf0e10cSrcweir CloseWindow();
666cdf0e10cSrcweir break;
667cdf0e10cSrcweir case DEPPOPUP_HELP :
668cdf0e10cSrcweir // DBG_ASSERT( FALSE,"help");
669cdf0e10cSrcweir ShowHelp();
670cdf0e10cSrcweir break;
671cdf0e10cSrcweir case DEPPOPUP_TEST :
672cdf0e10cSrcweir // DBG_ASSERT( FALSE,"TEST!");
673cdf0e10cSrcweir // test();
674cdf0e10cSrcweir break;
675cdf0e10cSrcweir case DEPPOPUP_SHOW_TOOLBOX:
676cdf0e10cSrcweir maToolBox.Show();
677cdf0e10cSrcweir break;
678cdf0e10cSrcweir default :
679cdf0e10cSrcweir DBG_ASSERT( sal_False, "default" );
680cdf0e10cSrcweir break;
681cdf0e10cSrcweir }
682cdf0e10cSrcweir return 0;
683cdf0e10cSrcweir }
684