1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlgassim.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #ifdef SD_DLLIMPLEMENTATION
35 #undef SD_DLLIMPLEMENTATION
37 #include <sfx2/docfile.hxx>
38 #include <tools/urlobj.hxx>
39 #include <svtools/pathoptions.hxx>
42 #include "Outliner.hxx"
43 #include "res_bmp.hrc"
45 #include <vcl/svapp.hxx>
47 #include "dlgassim.hxx"
49 SdPageListControl::SdPageListControl(
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();
74 if(pTreeModel
->IsAtRootDepth(pEntry
) && GetCheckButtonState( pEntry
) == SV_BUTTON_CHECKED
)
76 pEntry
= pTreeModel
->Next( pEntry
);
79 pEntry
= pTreeModel
->First();
80 SetCheckButtonState( pEntry
, SV_BUTTON_CHECKED
);
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
,
101 pEntry
->AddItem( new SvLBoxContextBmp( pEntry
, 0, Image(), Image(), 0)); // Sonst Puff!
102 pEntry
->AddItem( new SvLBoxString( pEntry
, 0, rPageName
) );
104 GetModel()->Insert( 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();
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
);
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
;
148 if (pTO
&& !pTO
->IsEmptyPresObj())
150 OutlinerParaObject
* pOPO
= pTO
->GetOutlinerParaObject();
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
);
179 USHORT
SdPageListControl::GetSelectedPage()
181 SvLBoxEntry
* pSelEntry
= GetCurEntry();
186 SvLBoxTreeList
* pTreeModel
= GetModel();
187 SvLBoxEntry
* pEntry
= pTreeModel
->First();
189 while( pEntry
&& pEntry
!= pSelEntry
)
191 if(pTreeModel
->IsAtRootDepth(pEntry
))
193 pEntry
= pTreeModel
->Next( pEntry
);
196 if(!pTreeModel
->IsAtRootDepth(pSelEntry
))
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 // ====================================================================
215 // ====================================================================
217 // Kennung fuer die Config Datei mit den Cache Daten
218 static const UINT16 nMagic
= (UINT16
)0x4127;
220 TemplateCacheInfo::TemplateCacheInfo()
227 TemplateCacheInfo::TemplateCacheInfo( const String
& rFile
, const DateTime
& rDateTime
, BOOL bImpress
)
230 m_aDateTime
= rDateTime
;
231 m_bImpress
= bImpress
;
236 SvStream
& operator >> (SvStream
& rIn
, TemplateCacheInfo
& rInfo
)
238 rIn
.ReadByteString( rInfo
.m_aFile
, RTL_TEXTENCODING_UTF8
);
239 USHORT nDay
, nMonth
, 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
;
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
;
266 SvStream
& operator << (SvStream
& rOut
, const TemplateCacheInfo
& rInfo
)
270 rOut
.WriteByteString( rInfo
.m_aFile
, RTL_TEXTENCODING_UTF8
);
272 nTemp
= rInfo
.m_aDateTime
.GetDay();
275 nTemp
= rInfo
.m_aDateTime
.GetMonth();
278 nTemp
= rInfo
.m_aDateTime
.GetYear();
281 nTemp
= rInfo
.m_aDateTime
.GetHour();
284 nTemp
= rInfo
.m_aDateTime
.GetMin();
287 nTemp
= rInfo
.m_aDateTime
.GetSec();
290 nTemp
= rInfo
.m_aDateTime
.Get100Sec();
293 rOut
<< rInfo
.m_bImpress
;
298 TemplateCache::TemplateCache()
302 TemplateCache::~TemplateCache()
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() )
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();
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
);
346 for( UINT16 nFile
= 0; pStream
->GetError() == SVSTREAM_OK
&& nFile
< nFiles
; nFile
++ )
348 TemplateCacheInfo
* pEntry
= new TemplateCacheInfo();
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
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();
371 UINT16 nCheck
= nMagic
;
374 const UINT16 nDirs
= (UINT16
) m_aDirs
.Count();
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();
386 for( TemplateCacheInfo
* pEntry
= pDir
->m_aFiles
.First();
387 pStream
->GetError() == SVSTREAM_OK
&& pEntry
;
388 pEntry
= pDir
->m_aFiles
.Next() )
395 TemplateCacheDirEntry
* TemplateCache::GetDirEntry( const String
& rPath
)
397 TemplateCacheDirEntry
* pDir
= m_aDirs
.GetCurObject();
398 if( pDir
&& pDir
->m_aPath
== rPath
)
401 for( pDir
= m_aDirs
.First(); pDir
; pDir
= m_aDirs
.Next() )
403 if( pDir
->m_aPath
== rPath
)
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
);
422 for( TemplateCacheInfo
* pEntry
= pDir
->m_aFiles
.First(); pEntry
; pEntry
= pDir
->m_aFiles
.Next() )
424 if( pEntry
->GetFile() == aName
)
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
;
445 pDir
= new TemplateCacheDirEntry();
446 pDir
->m_aPath
= aPath
;
447 m_aDirs
.Insert(pDir
);
452 for( pEntry
= pDir
->m_aFiles
.First(); pEntry
; pEntry
= pDir
->m_aFiles
.Next() )
454 if( pEntry
->GetFile() == aName
)
458 pEntry
= new TemplateCacheInfo();
459 pEntry
->SetFile( aName
);
460 pDir
->m_aFiles
.Insert(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
);
480 else if( pEntry
->IsModified() )
486 if( pDir
->m_aFiles
.Count() == 0 )
488 m_aDirs
.Remove(pDir
);