Update ooo320-m1
[ooovba.git] / sd / source / ui / dlg / dlgassim.cxx
blobf2181c45ceeb3b70a8776ed07ed7171efdc0a92a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlgassim.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #ifdef SD_DLLIMPLEMENTATION
35 #undef SD_DLLIMPLEMENTATION
36 #endif
37 #include <sfx2/docfile.hxx>
38 #include <tools/urlobj.hxx>
39 #include <svtools/pathoptions.hxx>
41 #include "sdpage.hxx"
42 #include "Outliner.hxx"
43 #include "res_bmp.hrc"
45 #include <vcl/svapp.hxx>
47 #include "dlgassim.hxx"
49 SdPageListControl::SdPageListControl(
50 ::Window* pParent,
51 const ResId& rResId )
52 : SvTreeListBox(pParent, rResId)
54 // Tree-ListBox mit Linien versehen
55 SetWindowBits( WinBits( WB_TABSTOP | WB_BORDER | WB_HASLINES |
56 WB_HASBUTTONS | WB_HASLINESATROOT |
57 WB_HSCROLL | // #31562#
58 WB_HASBUTTONSATROOT ) );
60 SetNodeDefaultImages ();
61 m_pCheckButton = new SvLBoxButtonData(this);
62 EnableCheckButton (m_pCheckButton);
64 SetCheckButtonHdl( LINK(this,SdPageListControl,CheckButtonClickHdl) );
67 IMPL_LINK( SdPageListControl, CheckButtonClickHdl, SvLBoxButtonData *, EMPTYARG )
69 SvLBoxTreeList* pTreeModel = GetModel();
70 SvLBoxEntry* pEntry = pTreeModel->First();
72 while( pEntry )
74 if(pTreeModel->IsAtRootDepth(pEntry) && GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED )
75 return 0;
76 pEntry = pTreeModel->Next( pEntry );
79 pEntry = pTreeModel->First();
80 SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
82 return 0;
85 SdPageListControl::~SdPageListControl()
87 delete m_pCheckButton;
90 void SdPageListControl::Clear()
92 SvTreeListBox::Clear();
95 SvLBoxEntry* SdPageListControl::InsertPage( const String& rPageName )
97 SvLBoxEntry* pEntry = new SvLBoxEntry;
99 pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
100 0, m_pCheckButton));
101 pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0)); // Sonst Puff!
102 pEntry->AddItem( new SvLBoxString( pEntry, 0, rPageName ) );
104 GetModel()->Insert( pEntry );
106 return pEntry;
109 void SdPageListControl::InsertTitle( SvLBoxEntry* pParent, const String& rTitle )
111 SvLBoxEntry* pEntry = new SvLBoxEntry;
112 pEntry->AddItem( new SvLBoxString( pEntry, 0, String() ) );
113 pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0)); // Sonst Puff!
114 pEntry->AddItem( new SvLBoxString( pEntry, 0, rTitle ) );
115 GetModel()->Insert( pEntry,pParent );
118 void SdPageListControl::Fill( SdDrawDocument* pDoc )
120 Outliner* pOutliner = pDoc->GetInternalOutliner();
122 USHORT nPage = 0;
123 const USHORT nMaxPages = pDoc->GetPageCount();
124 while( nPage < nMaxPages )
126 SdPage* pPage = (SdPage*) pDoc->GetPage( nPage );
127 if( pPage->GetPageKind() == PK_STANDARD )
129 SvLBoxEntry* pEntry = InsertPage( pPage->GetName() );
130 SetCheckButtonState(pEntry, SvButtonState( SV_BUTTON_CHECKED ) );
132 SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_TEXT);
133 if(!pTO)
135 // Ermittelt das SdrTextObject mit dem Layout Text dieser Seite
136 const ULONG nObjectCount = pPage->GetObjCount();
137 for (ULONG nObject = 0; nObject < nObjectCount; nObject++)
139 SdrObject* pObject = pPage->GetObj(nObject);
140 if (pObject->GetObjInventor() == SdrInventor && pObject->GetObjIdentifier() == OBJ_OUTLINETEXT)
142 pTO = (SdrTextObj*)pObject;
143 break;
148 if (pTO && !pTO->IsEmptyPresObj())
150 OutlinerParaObject* pOPO = pTO->GetOutlinerParaObject();
151 if (pOPO)
153 pOutliner->Clear();
154 pOutliner->SetText( *pOPO );
156 ULONG nCount = pOutliner->GetParagraphCount();
158 Paragraph* pPara = NULL;
160 for (ULONG nPara = 0; nPara < nCount; nPara++)
162 pPara = pOutliner->GetParagraph(nPara);
163 if(pPara && pOutliner->GetDepth( (USHORT) nPara ) == 0 )
165 String aParaText = pOutliner->GetText(pPara);
166 if(aParaText.Len() != 0)
167 InsertTitle( pEntry, aParaText );
173 nPage++;
176 pOutliner->Clear();
179 USHORT SdPageListControl::GetSelectedPage()
181 SvLBoxEntry* pSelEntry = GetCurEntry();
182 USHORT nPage = 0;
184 if ( pSelEntry )
186 SvLBoxTreeList* pTreeModel = GetModel();
187 SvLBoxEntry* pEntry = pTreeModel->First();
189 while( pEntry && pEntry != pSelEntry )
191 if(pTreeModel->IsAtRootDepth(pEntry))
192 nPage++;
193 pEntry = pTreeModel->Next( pEntry );
196 if(!pTreeModel->IsAtRootDepth(pSelEntry))
197 nPage--;
199 return nPage;
202 BOOL SdPageListControl::IsPageChecked( USHORT nPage )
204 SvLBoxEntry* pEntry = GetModel()->GetEntry(nPage);
205 return pEntry?(BOOL)(GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED): FALSE;
208 void SdPageListControl::DataChanged( const DataChangedEvent& rDCEvt )
210 SvTreeListBox::DataChanged( rDCEvt );
213 // ====================================================================
214 // TemplateCache
215 // ====================================================================
217 // Kennung fuer die Config Datei mit den Cache Daten
218 static const UINT16 nMagic = (UINT16)0x4127;
220 TemplateCacheInfo::TemplateCacheInfo()
222 m_bImpress = FALSE;
223 m_bValid = FALSE;
224 m_bModified = TRUE;
227 TemplateCacheInfo::TemplateCacheInfo( const String& rFile, const DateTime& rDateTime, BOOL bImpress )
229 m_aFile = rFile;
230 m_aDateTime = rDateTime;
231 m_bImpress = bImpress;
232 m_bValid = FALSE;
233 m_bModified = TRUE;
236 SvStream& operator >> (SvStream& rIn, TemplateCacheInfo& rInfo)
238 rIn.ReadByteString( rInfo.m_aFile, RTL_TEXTENCODING_UTF8 );
239 USHORT nDay, nMonth, nYear;
240 rIn >> nDay;
241 rIn >> nMonth;
242 rIn >> nYear;
243 rInfo.m_aDateTime.SetDay( nDay );
244 rInfo.m_aDateTime.SetMonth( nMonth );
245 rInfo.m_aDateTime.SetYear( nYear);
247 USHORT nHour, nMin, nSec, n100Sec;
249 rIn >> nHour;
250 rIn >> nMin;
251 rIn >> nSec;
252 rIn >> n100Sec;
254 rInfo.m_aDateTime.SetHour( nHour );
255 rInfo.m_aDateTime.SetMin( nMin );
256 rInfo.m_aDateTime.SetSec( nSec );
257 rInfo.m_aDateTime.Set100Sec( n100Sec );
259 rIn >> rInfo.m_bImpress;
261 rInfo.m_bModified = FALSE;
263 return rIn;
266 SvStream& operator << (SvStream& rOut, const TemplateCacheInfo& rInfo)
268 USHORT nTemp;
270 rOut.WriteByteString( rInfo.m_aFile, RTL_TEXTENCODING_UTF8 );
272 nTemp = rInfo.m_aDateTime.GetDay();
273 rOut << nTemp;
275 nTemp = rInfo.m_aDateTime.GetMonth();
276 rOut << nTemp;
278 nTemp = rInfo.m_aDateTime.GetYear();
279 rOut << nTemp;
281 nTemp = rInfo.m_aDateTime.GetHour();
282 rOut << nTemp;
284 nTemp = rInfo.m_aDateTime.GetMin();
285 rOut << nTemp;
287 nTemp = rInfo.m_aDateTime.GetSec();
288 rOut << nTemp;
290 nTemp = rInfo.m_aDateTime.Get100Sec();
291 rOut << nTemp;
293 rOut << rInfo.m_bImpress;
295 return rOut;
298 TemplateCache::TemplateCache()
302 TemplateCache::~TemplateCache()
304 Clear();
307 void TemplateCache::Clear()
309 for( TemplateCacheDirEntry* pDir = m_aDirs.First(); pDir; pDir = m_aDirs.Next() )
311 for( TemplateCacheInfo* pEntry = pDir->m_aFiles.First(); pEntry; pEntry = pDir->m_aFiles.Next() )
312 delete pEntry;
313 delete pDir;
317 void TemplateCache::Load()
319 INetURLObject aURL( SvtPathOptions().GetUserConfigPath() );
320 aURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( "template.sod" ) ) );
321 SfxMedium aMedium( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ | STREAM_NOCREATE, TRUE ); // Download
322 SvStream* pStream = aMedium.GetInStream();
324 if( !pStream )
325 return;
327 UINT16 aCheck;
328 *pStream >> aCheck;
330 if(aCheck != nMagic)
331 return;
333 UINT16 nDirs;
334 *pStream >> nDirs;
336 for( UINT16 nDir = 0; pStream->GetError() == SVSTREAM_OK && nDir < nDirs; nDir++ )
338 TemplateCacheDirEntry* pDir = new TemplateCacheDirEntry();
339 m_aDirs.Insert(pDir);
341 pStream->ReadByteString( pDir->m_aPath, RTL_TEXTENCODING_UTF8 );
343 UINT16 nFiles;
344 *pStream >> nFiles;
346 for( UINT16 nFile = 0; pStream->GetError() == SVSTREAM_OK && nFile < nFiles; nFile++ )
348 TemplateCacheInfo* pEntry = new TemplateCacheInfo();
349 *pStream >> *pEntry;
350 pDir->m_aFiles.Insert(pEntry);
354 if( pStream->GetError() != SVSTREAM_OK )
356 // Ein I/O Problem ist doch kein Beinbruch, dann wird der Cache halt neu erzeugt
357 Clear();
361 void TemplateCache::Save()
363 INetURLObject aURL( SvtPathOptions().GetUserConfigPath() );
364 aURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( "template.sod" ) ) );
365 SfxMedium aMedium( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC, FALSE ); // Download
366 SvStream* pStream = aMedium.GetInStream();
368 if( !pStream )
369 return;
371 UINT16 nCheck = nMagic;
372 *pStream << nCheck;
374 const UINT16 nDirs = (UINT16) m_aDirs.Count();
375 *pStream << nDirs;
377 for( TemplateCacheDirEntry* pDir = m_aDirs.First();
378 pStream->GetError() == SVSTREAM_OK && pDir;
379 pDir = m_aDirs.Next() )
381 pStream->WriteByteString( pDir->m_aPath, RTL_TEXTENCODING_UTF8 );
383 const UINT16 nFiles = (UINT16) pDir->m_aFiles.Count();
384 *pStream << nFiles;
386 for( TemplateCacheInfo* pEntry = pDir->m_aFiles.First();
387 pStream->GetError() == SVSTREAM_OK && pEntry;
388 pEntry = pDir->m_aFiles.Next() )
390 *pStream << *pEntry;
395 TemplateCacheDirEntry* TemplateCache::GetDirEntry( const String& rPath )
397 TemplateCacheDirEntry* pDir = m_aDirs.GetCurObject();
398 if( pDir && pDir->m_aPath == rPath )
399 return pDir;
401 for( pDir = m_aDirs.First(); pDir; pDir = m_aDirs.Next() )
403 if( pDir->m_aPath == rPath )
404 return pDir;
407 return NULL;
410 TemplateCacheInfo* TemplateCache::GetFileInfo( const String& rPath )
412 INetURLObject aUrl( rPath );
413 String aPath( aUrl.GetPath() );
414 String aName( aUrl.GetName( INetURLObject::DECODE_UNAMBIGUOUS ) );
416 DBG_ASSERT( aUrl.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
418 TemplateCacheDirEntry* pDir = GetDirEntry( aPath );
420 if( NULL != pDir )
422 for( TemplateCacheInfo* pEntry = pDir->m_aFiles.First(); pEntry; pEntry = pDir->m_aFiles.Next() )
424 if( pEntry->GetFile() == aName )
425 return pEntry;
429 return NULL;
432 TemplateCacheInfo* TemplateCache::AddFileInfo( const String& rPath )
434 INetURLObject aUrl( rPath );
435 String aPath( aUrl.GetPath() );
436 String aName( aUrl.GetName( INetURLObject::DECODE_UNAMBIGUOUS ) );
438 DBG_ASSERT( aUrl.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
440 TemplateCacheDirEntry* pDir = GetDirEntry( aPath );
441 TemplateCacheInfo* pEntry = NULL;
443 if( pDir == NULL )
445 pDir = new TemplateCacheDirEntry();
446 pDir->m_aPath = aPath;
447 m_aDirs.Insert(pDir);
450 if( NULL != pDir )
452 for( pEntry = pDir->m_aFiles.First(); pEntry; pEntry = pDir->m_aFiles.Next() )
454 if( pEntry->GetFile() == aName)
455 return pEntry;
458 pEntry = new TemplateCacheInfo();
459 pEntry->SetFile( aName );
460 pDir->m_aFiles.Insert(pEntry);
463 return pEntry;
466 BOOL TemplateCache::ClearInvalidEntrys()
468 BOOL bModified = FALSE;
470 for( TemplateCacheDirEntry* pDir = m_aDirs.First(); pDir; pDir = m_aDirs.Next() )
472 for( TemplateCacheInfo* pEntry = pDir->m_aFiles.First(); pEntry; pEntry = pDir->m_aFiles.Next() )
474 if(!pEntry->IsValid())
476 pDir->m_aFiles.Remove(pEntry);
477 delete pEntry;
478 bModified = TRUE;
480 else if( pEntry->IsModified() )
482 bModified = TRUE;
486 if( pDir->m_aFiles.Count() == 0 )
488 m_aDirs.Remove(pDir);
489 delete pDir;
493 return bModified;