1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*f6e50924SAndrew Rist * distributed with this work for additional information
6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at
10*f6e50924SAndrew Rist *
11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist *
13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the
17*f6e50924SAndrew Rist * specific language governing permissions and limitations
18*f6e50924SAndrew Rist * under the License.
19*f6e50924SAndrew Rist *
20*f6e50924SAndrew Rist *************************************************************/
21*f6e50924SAndrew Rist
22*f6e50924SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <vector>
28cdf0e10cSrcweir #include <map>
29cdf0e10cSrcweir #include <algorithm>
30cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
31cdf0e10cSrcweir #include <sot/storage.hxx>
32cdf0e10cSrcweir #ifndef _SVTOOLS_HRC
33cdf0e10cSrcweir #include <svtools/svtools.hrc>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <sal/main.h>
37cdf0e10cSrcweir #include <vcl/event.hxx>
38cdf0e10cSrcweir #include <vcl/svapp.hxx>
39cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
40cdf0e10cSrcweir #include <vcl/msgbox.hxx>
41cdf0e10cSrcweir #include <vcl/fixed.hxx>
42cdf0e10cSrcweir #include <vcl/edit.hxx>
43cdf0e10cSrcweir #include <vcl/button.hxx>
44cdf0e10cSrcweir #include <vcl/lstbox.hxx>
45cdf0e10cSrcweir #include <svtools/filectrl.hxx>
46cdf0e10cSrcweir #include <tools/urlobj.hxx>
47cdf0e10cSrcweir #include <osl/file.hxx>
48cdf0e10cSrcweir #include <vcl/unohelp2.hxx>
49cdf0e10cSrcweir #include <svtools/svtreebx.hxx>
50cdf0e10cSrcweir #include <svtools/svmedit.hxx>
51cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
52cdf0e10cSrcweir
53cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
54cdf0e10cSrcweir
55cdf0e10cSrcweir #include <tools/stream.hxx>
56cdf0e10cSrcweir #include <tools/resmgr.hxx>
57cdf0e10cSrcweir
58cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
59cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
60cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
61cdf0e10cSrcweir
62cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
63cdf0e10cSrcweir #include <ucbhelper/configurationkeys.hxx>
64cdf0e10cSrcweir
65cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
66cdf0e10cSrcweir
67cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp>
68cdf0e10cSrcweir #include <com/sun/star/awt/XToolkit.hpp>
69cdf0e10cSrcweir #include <com/sun/star/awt/WindowDescriptor.hpp>
70cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
71cdf0e10cSrcweir #include <svx/msdffdef.hxx>
72cdf0e10cSrcweir
73cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
74cdf0e10cSrcweir
75cdf0e10cSrcweir #include "xmlconfig.hxx"
76cdf0e10cSrcweir
77cdf0e10cSrcweir using ::rtl::OUString;
78cdf0e10cSrcweir
79cdf0e10cSrcweir using namespace ::com::sun::star;
80cdf0e10cSrcweir
81cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
82cdf0e10cSrcweir
83cdf0e10cSrcweir enum CompareStatus { CMP_NOTYET = 0, CMP_EQUAL = 1, CMP_NOTEQUAL = 2, CMP_NOTAVAILABLE = 3 };
84cdf0e10cSrcweir static ColorData gColors[] = { COL_BLACK, COL_GREEN, COL_RED, COL_CYAN };
85cdf0e10cSrcweir
86cdf0e10cSrcweir class Atom
87cdf0e10cSrcweir {
88cdf0e10cSrcweir public:
89cdf0e10cSrcweir ~Atom();
90cdf0e10cSrcweir
91cdf0e10cSrcweir /** imports this atom and its child atoms */
92cdf0e10cSrcweir static Atom* import( const DffRecordHeader& rRootRecordHeader, SvStream& rStCtrl );
93cdf0e10cSrcweir static Atom* import( UINT16 nRecType, SvStream& rStCtrl );
94cdf0e10cSrcweir
95cdf0e10cSrcweir inline const DffRecordHeader& getHeader() const;
96cdf0e10cSrcweir
97cdf0e10cSrcweir /** returns true if at least one atim with the given nRecType is found */
98cdf0e10cSrcweir inline bool hasChildAtom( sal_uInt16 nRecType ) const;
99cdf0e10cSrcweir
100cdf0e10cSrcweir /** returns true if at least one atim with the given nRecType and nRecInstnace is found */
101cdf0e10cSrcweir inline bool hasChildAtom( sal_uInt16 nRecType, sal_uInt16 nRecInstance ) const;
102cdf0e10cSrcweir
103cdf0e10cSrcweir /** returns the first child atom with nRecType or NULL */
104cdf0e10cSrcweir inline const Atom* findFirstChildAtom( sal_uInt16 nRecType ) const;
105cdf0e10cSrcweir
106cdf0e10cSrcweir /** returns the next child atom after pLast with nRecType or NULL */
107cdf0e10cSrcweir const Atom* findNextChildAtom( sal_uInt16 nRecType, const Atom* pLast ) const;
108cdf0e10cSrcweir
109cdf0e10cSrcweir /** returns the first child atom with nRecType and nRecInstance or NULL */
110cdf0e10cSrcweir inline const Atom* findFirstChildAtom( sal_uInt16 nRecType, sal_uInt16 nRecInstance ) const;
111cdf0e10cSrcweir
112cdf0e10cSrcweir /** returns the next child atom after pLast with nRecType and nRecInstance or NULL */
113cdf0e10cSrcweir const Atom* findNextChildAtom( sal_uInt16 nRecType, sal_uInt16 nRecInstance, const Atom* pLast ) const;
114cdf0e10cSrcweir
115cdf0e10cSrcweir /** returns the first child atom or NULL */
116cdf0e10cSrcweir inline const Atom* findFirstChildAtom() const;
117cdf0e10cSrcweir
118cdf0e10cSrcweir /** returns the next child atom after pLast or NULL */
119cdf0e10cSrcweir inline const Atom* findNextChildAtom( const Atom* pLast ) const;
120cdf0e10cSrcweir
121cdf0e10cSrcweir /** returns true if this atom is a container */
122cdf0e10cSrcweir inline bool isContainer() const;
123cdf0e10cSrcweir
124cdf0e10cSrcweir /** seeks to the contents of this atom */
125cdf0e10cSrcweir inline bool seekToContent() const;
126cdf0e10cSrcweir
127cdf0e10cSrcweir /** returns the record type */
128cdf0e10cSrcweir inline sal_uInt16 getType() const;
129cdf0e10cSrcweir
130cdf0e10cSrcweir /** returns the record instance */
131cdf0e10cSrcweir inline sal_uInt16 getInstance() const;
132cdf0e10cSrcweir
133cdf0e10cSrcweir /** returns the record length */
134cdf0e10cSrcweir inline sal_uInt32 getLength() const;
135cdf0e10cSrcweir
getStream() const136cdf0e10cSrcweir SvStream& getStream() const { return mrStream; }
137cdf0e10cSrcweir
138cdf0e10cSrcweir bool operator==( const Atom& rAtom ) const;
139cdf0e10cSrcweir
getCompareStatus() const140cdf0e10cSrcweir CompareStatus getCompareStatus() const { return meStatus; }
141cdf0e10cSrcweir
142cdf0e10cSrcweir void compare( Atom* pAtom );
143cdf0e10cSrcweir bool compareContent( Atom& rAtom );
144cdf0e10cSrcweir
getCompareAtom() const145cdf0e10cSrcweir Atom* getCompareAtom() const { return mpCompareAtom; }
setCompareAtom(Atom * pAtom)146cdf0e10cSrcweir void setCompareAtom( Atom* pAtom ) { mpCompareAtom = pAtom; }
147cdf0e10cSrcweir
148cdf0e10cSrcweir private:
149cdf0e10cSrcweir Atom( const DffRecordHeader& rRecordHeader, SvStream& rStCtrl );
150cdf0e10cSrcweir
151cdf0e10cSrcweir // statics for compare
152cdf0e10cSrcweir static Atom* skipAtoms( Atom* pContainer, Atom* pAtom, Atom* pSkipTo );
153cdf0e10cSrcweir static Atom* findFirstEqualAtom( Atom* pCompare, Atom* pContainer, Atom* pSearch, int& nDistance );
154cdf0e10cSrcweir
155cdf0e10cSrcweir SvStream& mrStream;
156cdf0e10cSrcweir DffRecordHeader maRecordHeader;
157cdf0e10cSrcweir Atom* mpFirstChild;
158cdf0e10cSrcweir Atom* mpNextAtom;
159cdf0e10cSrcweir
160cdf0e10cSrcweir CompareStatus meStatus;
161cdf0e10cSrcweir Atom* mpCompareAtom;
162cdf0e10cSrcweir };
163cdf0e10cSrcweir
operator ==(const Atom & rAtom) const164cdf0e10cSrcweir bool Atom::operator==( const Atom& rAtom ) const
165cdf0e10cSrcweir {
166cdf0e10cSrcweir return ( maRecordHeader.nRecType == rAtom.maRecordHeader.nRecType ) &&
167cdf0e10cSrcweir ( maRecordHeader.nRecVer == rAtom.maRecordHeader.nRecVer ) &&
168cdf0e10cSrcweir ( maRecordHeader.nRecInstance == rAtom.maRecordHeader.nRecInstance );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
compareContent(Atom & rAtom)171cdf0e10cSrcweir bool Atom::compareContent( Atom& rAtom )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir if( maRecordHeader.nRecLen == rAtom.maRecordHeader.nRecLen )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir seekToContent();
176cdf0e10cSrcweir rAtom.seekToContent();
177cdf0e10cSrcweir
178cdf0e10cSrcweir SvStream& rStream1 = getStream();
179cdf0e10cSrcweir SvStream& rStream2 = rAtom.getStream();
180cdf0e10cSrcweir
181cdf0e10cSrcweir const int nBufferSize = 1024;
182cdf0e10cSrcweir boost::shared_ptr< char > buffer1( new char[nBufferSize] );
183cdf0e10cSrcweir boost::shared_ptr< char > buffer2( new char[nBufferSize] );
184cdf0e10cSrcweir
185cdf0e10cSrcweir sal_uInt32 nLength = maRecordHeader.nRecLen;
186cdf0e10cSrcweir sal_Size nRead = 0;
187cdf0e10cSrcweir while( nLength )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir sal_Size nRead = (nBufferSize < nLength) ? nBufferSize : nLength;
190cdf0e10cSrcweir nRead = rStream1.Read( (void*)buffer1.get(), nRead );
191cdf0e10cSrcweir if( nRead == 0 )
192cdf0e10cSrcweir break;
193cdf0e10cSrcweir if( rStream2.Read( (void*)buffer2.get(), nRead ) != nRead )
194cdf0e10cSrcweir break;
195cdf0e10cSrcweir if( memcmp( (void*)buffer1.get(), (void*)buffer2.get(), nRead ) != 0 )
196cdf0e10cSrcweir break;
197cdf0e10cSrcweir
198cdf0e10cSrcweir nLength -= nRead;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir
201cdf0e10cSrcweir return nLength == 0;
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
204cdf0e10cSrcweir return false;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
hasChildAtom(sal_uInt16 nRecType) const207cdf0e10cSrcweir inline bool Atom::hasChildAtom( sal_uInt16 nRecType ) const
208cdf0e10cSrcweir {
209cdf0e10cSrcweir return findFirstChildAtom( nRecType ) != NULL;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
hasChildAtom(sal_uInt16 nRecType,sal_uInt16 nRecInstance) const212cdf0e10cSrcweir inline bool Atom::hasChildAtom( sal_uInt16 nRecType, sal_uInt16 nRecInstance ) const
213cdf0e10cSrcweir {
214cdf0e10cSrcweir return findFirstChildAtom( nRecType, nRecInstance ) != NULL;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
findFirstChildAtom(sal_uInt16 nRecType) const217cdf0e10cSrcweir inline const Atom* Atom::findFirstChildAtom( sal_uInt16 nRecType ) const
218cdf0e10cSrcweir {
219cdf0e10cSrcweir return findNextChildAtom( nRecType, NULL );
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
getHeader() const222cdf0e10cSrcweir inline const DffRecordHeader& Atom::getHeader() const
223cdf0e10cSrcweir {
224cdf0e10cSrcweir return maRecordHeader;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
findFirstChildAtom(sal_uInt16 nRecType,sal_uInt16 nRecInstance) const227cdf0e10cSrcweir inline const Atom* Atom::findFirstChildAtom( sal_uInt16 nRecType, sal_uInt16 nRecInstance ) const
228cdf0e10cSrcweir {
229cdf0e10cSrcweir return findNextChildAtom( nRecType, nRecInstance, NULL );
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
findFirstChildAtom() const232cdf0e10cSrcweir inline const Atom* Atom::findFirstChildAtom() const
233cdf0e10cSrcweir {
234cdf0e10cSrcweir return mpFirstChild;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir
findNextChildAtom(const Atom * pLast) const237cdf0e10cSrcweir inline const Atom* Atom::findNextChildAtom( const Atom* pLast ) const
238cdf0e10cSrcweir {
239cdf0e10cSrcweir return pLast ? pLast->mpNextAtom : pLast;
240cdf0e10cSrcweir }
241cdf0e10cSrcweir
isContainer() const242cdf0e10cSrcweir inline bool Atom::isContainer() const
243cdf0e10cSrcweir {
244cdf0e10cSrcweir return (bool)maRecordHeader.IsContainer();
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
seekToContent() const247cdf0e10cSrcweir inline bool Atom::seekToContent() const
248cdf0e10cSrcweir {
249cdf0e10cSrcweir maRecordHeader.SeekToContent( mrStream );
250cdf0e10cSrcweir return mrStream.GetError() == 0;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir
getType() const253cdf0e10cSrcweir inline sal_uInt16 Atom::getType() const
254cdf0e10cSrcweir {
255cdf0e10cSrcweir return maRecordHeader.nRecType;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir
getInstance() const258cdf0e10cSrcweir inline sal_uInt16 Atom::getInstance() const
259cdf0e10cSrcweir {
260cdf0e10cSrcweir return maRecordHeader.nRecInstance;
261cdf0e10cSrcweir }
262cdf0e10cSrcweir
getLength() const263cdf0e10cSrcweir inline sal_uInt32 Atom::getLength() const
264cdf0e10cSrcweir {
265cdf0e10cSrcweir return maRecordHeader.nRecLen;
266cdf0e10cSrcweir }
267cdf0e10cSrcweir
Atom(const DffRecordHeader & rRecordHeader,SvStream & rStream)268cdf0e10cSrcweir Atom::Atom( const DffRecordHeader& rRecordHeader, SvStream& rStream )
269cdf0e10cSrcweir : maRecordHeader( rRecordHeader ),
270cdf0e10cSrcweir mrStream( rStream ),
271cdf0e10cSrcweir mpFirstChild( 0 ),
272cdf0e10cSrcweir mpNextAtom( 0 ),
273cdf0e10cSrcweir meStatus( CMP_NOTYET ),
274cdf0e10cSrcweir mpCompareAtom( 0 )
275cdf0e10cSrcweir {
276cdf0e10cSrcweir // check if we need to force this to a container
277cdf0e10cSrcweir if( maRecordHeader.nRecVer != DFF_PSFLAG_CONTAINER )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir AtomConfig* pAtomConfig = dynamic_cast< AtomConfig* >( gAtomConfigMap[ maRecordHeader.nRecType ].get() );
280cdf0e10cSrcweir if( pAtomConfig && pAtomConfig->isContainer() )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir maRecordHeader.nRecVer = DFF_PSFLAG_CONTAINER;
283cdf0e10cSrcweir }
284cdf0e10cSrcweir }
285cdf0e10cSrcweir
286cdf0e10cSrcweir if( isContainer() )
287cdf0e10cSrcweir {
288cdf0e10cSrcweir if( seekToContent() )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir DffRecordHeader aChildHeader;
291cdf0e10cSrcweir
292cdf0e10cSrcweir Atom* pLastAtom = NULL;
293cdf0e10cSrcweir
294cdf0e10cSrcweir while( (mrStream.GetError() == 0 ) && ( mrStream.Tell() < maRecordHeader.GetRecEndFilePos() ) )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir mrStream >> aChildHeader;
297cdf0e10cSrcweir
298cdf0e10cSrcweir if( mrStream.GetError() == 0 )
299cdf0e10cSrcweir {
300cdf0e10cSrcweir Atom* pAtom = new Atom( aChildHeader, mrStream );
301cdf0e10cSrcweir
302cdf0e10cSrcweir if( pLastAtom )
303cdf0e10cSrcweir pLastAtom->mpNextAtom = pAtom;
304cdf0e10cSrcweir if( mpFirstChild == NULL )
305cdf0e10cSrcweir mpFirstChild = pAtom;
306cdf0e10cSrcweir
307cdf0e10cSrcweir pLastAtom = pAtom;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir }
310cdf0e10cSrcweir }
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
313cdf0e10cSrcweir maRecordHeader.SeekToEndOfRecord( mrStream );
314cdf0e10cSrcweir }
315cdf0e10cSrcweir
~Atom()316cdf0e10cSrcweir Atom::~Atom()
317cdf0e10cSrcweir {
318cdf0e10cSrcweir Atom* pChild = mpFirstChild;
319cdf0e10cSrcweir while( pChild )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir Atom* pNextChild = pChild->mpNextAtom;
322cdf0e10cSrcweir delete pChild;
323cdf0e10cSrcweir pChild = pNextChild;
324cdf0e10cSrcweir }
325cdf0e10cSrcweir }
326cdf0e10cSrcweir
327cdf0e10cSrcweir /** imports this atom and its child atoms */
import(const DffRecordHeader & rRootRecordHeader,SvStream & rStCtrl)328cdf0e10cSrcweir Atom* Atom::import( const DffRecordHeader& rRootRecordHeader, SvStream& rStCtrl )
329cdf0e10cSrcweir {
330cdf0e10cSrcweir Atom* pRootAtom = new Atom( rRootRecordHeader, rStCtrl );
331cdf0e10cSrcweir
332cdf0e10cSrcweir if( rStCtrl.GetError() == 0 )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir return pRootAtom;
335cdf0e10cSrcweir }
336cdf0e10cSrcweir else
337cdf0e10cSrcweir {
338cdf0e10cSrcweir delete pRootAtom;
339cdf0e10cSrcweir return NULL;
340cdf0e10cSrcweir }
341cdf0e10cSrcweir }
342cdf0e10cSrcweir
343cdf0e10cSrcweir /** imports this atom and its child atoms */
import(UINT16 nRecType,SvStream & rStCtrl)344cdf0e10cSrcweir Atom* Atom::import( UINT16 nRecType, SvStream& rStCtrl )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir rStCtrl.Seek( STREAM_SEEK_TO_END );
347cdf0e10cSrcweir sal_Size nStreamLength = rStCtrl.Tell();
348cdf0e10cSrcweir rStCtrl.Seek( STREAM_SEEK_TO_BEGIN );
349cdf0e10cSrcweir
350cdf0e10cSrcweir DffRecordHeader aRootRecordHeader;
351cdf0e10cSrcweir aRootRecordHeader.nRecVer = DFF_PSFLAG_CONTAINER;
352cdf0e10cSrcweir aRootRecordHeader.nRecInstance = 0;
353cdf0e10cSrcweir aRootRecordHeader.nImpVerInst = 0;
354cdf0e10cSrcweir aRootRecordHeader.nRecType = nRecType;
355cdf0e10cSrcweir aRootRecordHeader.nRecLen = nStreamLength;
356cdf0e10cSrcweir aRootRecordHeader.nFilePos = 0;
357cdf0e10cSrcweir
358cdf0e10cSrcweir return import( aRootRecordHeader, rStCtrl );
359cdf0e10cSrcweir }
360cdf0e10cSrcweir
361cdf0e10cSrcweir /** returns the next child atom after pLast with nRecType or NULL */
findNextChildAtom(sal_uInt16 nRecType,const Atom * pLast) const362cdf0e10cSrcweir const Atom* Atom::findNextChildAtom( sal_uInt16 nRecType, const Atom* pLast ) const
363cdf0e10cSrcweir {
364cdf0e10cSrcweir Atom* pChild = pLast != NULL ? pLast->mpNextAtom : mpFirstChild;
365cdf0e10cSrcweir while( pChild && pChild->maRecordHeader.nRecType != nRecType )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir pChild = pChild->mpNextAtom;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir
370cdf0e10cSrcweir return pChild;
371cdf0e10cSrcweir }
372cdf0e10cSrcweir
373cdf0e10cSrcweir /** returns the next child atom after pLast with nRecType and nRecInstance or NULL */
findNextChildAtom(sal_uInt16 nRecType,sal_uInt16 nRecInstance,const Atom * pLast) const374cdf0e10cSrcweir const Atom* Atom::findNextChildAtom( sal_uInt16 nRecType, sal_uInt16 nRecInstance, const Atom* pLast ) const
375cdf0e10cSrcweir {
376cdf0e10cSrcweir const Atom* pChild = pLast != NULL ? pLast->mpNextAtom : mpFirstChild;
377cdf0e10cSrcweir while( pChild && (pChild->maRecordHeader.nRecType != nRecType) && (pChild->maRecordHeader.nRecInstance != nRecInstance) )
378cdf0e10cSrcweir {
379cdf0e10cSrcweir pChild = findNextChildAtom( pChild );
380cdf0e10cSrcweir }
381cdf0e10cSrcweir
382cdf0e10cSrcweir return pChild;
383cdf0e10cSrcweir }
384cdf0e10cSrcweir
findFirstEqualAtom(Atom * pCompare,Atom * pContainer,Atom * pSearch,int & nDistance)385cdf0e10cSrcweir Atom* Atom::findFirstEqualAtom( Atom* pCompare, Atom* pContainer, Atom* pSearch, int& nDistance )
386cdf0e10cSrcweir {
387cdf0e10cSrcweir nDistance = 0;
388cdf0e10cSrcweir Atom* pRet = 0;
389cdf0e10cSrcweir
390cdf0e10cSrcweir while( pSearch )
391cdf0e10cSrcweir {
392cdf0e10cSrcweir if( *pSearch == *pCompare )
393cdf0e10cSrcweir return pSearch;
394cdf0e10cSrcweir
395cdf0e10cSrcweir pSearch = const_cast< Atom* >( pContainer->findNextChildAtom( pSearch ) );
396cdf0e10cSrcweir nDistance++;
397cdf0e10cSrcweir }
398cdf0e10cSrcweir
399cdf0e10cSrcweir return 0;
400cdf0e10cSrcweir }
401cdf0e10cSrcweir
skipAtoms(Atom * pContainer,Atom * pAtom,Atom * pSkipTo)402cdf0e10cSrcweir Atom* Atom::skipAtoms( Atom* pContainer, Atom* pAtom, Atom* pSkipTo )
403cdf0e10cSrcweir {
404cdf0e10cSrcweir while( pAtom && (pAtom != pSkipTo) )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir pAtom->meStatus = CMP_NOTAVAILABLE;
407cdf0e10cSrcweir pAtom = const_cast< Atom* >( pContainer->findNextChildAtom( pAtom ) );
408cdf0e10cSrcweir }
409cdf0e10cSrcweir
410cdf0e10cSrcweir return pAtom;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir
compare(Atom * pAtom)413cdf0e10cSrcweir void Atom::compare( Atom* pAtom )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir if( pAtom )
416cdf0e10cSrcweir {
417cdf0e10cSrcweir if( meStatus == CMP_NOTYET )
418cdf0e10cSrcweir {
419cdf0e10cSrcweir mpCompareAtom = pAtom;
420cdf0e10cSrcweir pAtom->mpCompareAtom = this;
421cdf0e10cSrcweir
422cdf0e10cSrcweir mpCompareAtom = pAtom;
423cdf0e10cSrcweir pAtom->mpCompareAtom = this;
424cdf0e10cSrcweir
425cdf0e10cSrcweir meStatus = pAtom->meStatus = ( *this == *pAtom ) ? CMP_EQUAL : CMP_NOTEQUAL;
426cdf0e10cSrcweir }
427cdf0e10cSrcweir
428cdf0e10cSrcweir if(meStatus == CMP_EQUAL)
429cdf0e10cSrcweir {
430cdf0e10cSrcweir if( isContainer() )
431cdf0e10cSrcweir {
432cdf0e10cSrcweir /** returns the first child atom or NULL */
433cdf0e10cSrcweir Atom* pChildAtom1 = const_cast< Atom* >( findFirstChildAtom() );
434cdf0e10cSrcweir
435cdf0e10cSrcweir if( pChildAtom1 && (pChildAtom1->meStatus == CMP_NOTYET) )
436cdf0e10cSrcweir {
437cdf0e10cSrcweir Atom* pChildAtom2 = const_cast< Atom* >( pAtom->findFirstChildAtom() );
438cdf0e10cSrcweir while( pChildAtom1 && pChildAtom2 )
439cdf0e10cSrcweir {
440cdf0e10cSrcweir if( !(*pChildAtom1 == *pChildAtom2) )
441cdf0e10cSrcweir {
442cdf0e10cSrcweir int nDistance1;
443cdf0e10cSrcweir int nDistance2;
444cdf0e10cSrcweir
445cdf0e10cSrcweir Atom* pFind1 = findFirstEqualAtom( pChildAtom1, pAtom, const_cast< Atom* >( pAtom->findNextChildAtom( pChildAtom2 )), nDistance1 );
446cdf0e10cSrcweir Atom* pFind2 = findFirstEqualAtom( pChildAtom2, this, const_cast< Atom* >(findNextChildAtom( pChildAtom1 )), nDistance2 );
447cdf0e10cSrcweir
448cdf0e10cSrcweir if( pFind1 && (!pFind2 || (nDistance1 < nDistance2) ) )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir pChildAtom2 = skipAtoms( pAtom, pChildAtom2, pFind1 );
451cdf0e10cSrcweir }
452cdf0e10cSrcweir else if( pFind2 )
453cdf0e10cSrcweir {
454cdf0e10cSrcweir pChildAtom1 = skipAtoms( this, pChildAtom1, pFind2 );
455cdf0e10cSrcweir }
456cdf0e10cSrcweir else
457cdf0e10cSrcweir {
458cdf0e10cSrcweir pChildAtom1 = skipAtoms( this, pChildAtom1, 0 );
459cdf0e10cSrcweir pChildAtom2 = skipAtoms( pAtom, pChildAtom2, 0 );
460cdf0e10cSrcweir }
461cdf0e10cSrcweir }
462cdf0e10cSrcweir
463cdf0e10cSrcweir if( pChildAtom1 && pChildAtom2 )
464cdf0e10cSrcweir {
465cdf0e10cSrcweir pChildAtom1->mpCompareAtom = pChildAtom2;
466cdf0e10cSrcweir pChildAtom2->mpCompareAtom = pChildAtom1;
467cdf0e10cSrcweir
468cdf0e10cSrcweir pChildAtom1->meStatus = pChildAtom2->meStatus =
469cdf0e10cSrcweir (pChildAtom1->isContainer() || pChildAtom1->compareContent( *pChildAtom2 )) ?
470cdf0e10cSrcweir CMP_EQUAL : CMP_NOTEQUAL;
471cdf0e10cSrcweir
472cdf0e10cSrcweir pChildAtom1 = const_cast< Atom* >( findNextChildAtom( pChildAtom1 ) );
473cdf0e10cSrcweir pChildAtom2 = const_cast< Atom* >( pAtom->findNextChildAtom( pChildAtom2 ) );
474cdf0e10cSrcweir }
475cdf0e10cSrcweir }
476cdf0e10cSrcweir }
477cdf0e10cSrcweir }
478cdf0e10cSrcweir else
479cdf0e10cSrcweir {
480cdf0e10cSrcweir if( !compareContent( *pAtom ) )
481cdf0e10cSrcweir {
482cdf0e10cSrcweir meStatus = pAtom->meStatus = CMP_NOTEQUAL;
483cdf0e10cSrcweir }
484cdf0e10cSrcweir }
485cdf0e10cSrcweir }
486cdf0e10cSrcweir }
487cdf0e10cSrcweir }
488cdf0e10cSrcweir
489cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
490cdf0e10cSrcweir
491cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
492cdf0e10cSrcweir
493cdf0e10cSrcweir class AtomBoxString : public SvLBoxString
494cdf0e10cSrcweir {
495cdf0e10cSrcweir public:
AtomBoxString(SvLBoxEntry * pEntry,const String & rStr)496cdf0e10cSrcweir AtomBoxString( SvLBoxEntry* pEntry, const String& rStr )
497cdf0e10cSrcweir : SvLBoxString( pEntry, 0, rStr )
498cdf0e10cSrcweir { }
499cdf0e10cSrcweir
~AtomBoxString()500cdf0e10cSrcweir ~AtomBoxString() { }
501cdf0e10cSrcweir
Paint(const Point & rPos,SvLBox & rOutDev,USHORT nViewDataEntryFlags,SvLBoxEntry * pEntry)502cdf0e10cSrcweir void Paint( const Point& rPos, SvLBox& rOutDev, USHORT nViewDataEntryFlags, SvLBoxEntry* pEntry )
503cdf0e10cSrcweir {
504cdf0e10cSrcweir Color aOldTextColor = rOutDev.GetTextColor();
505cdf0e10cSrcweir
506cdf0e10cSrcweir if( pEntry && pEntry->GetUserData() )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir Atom* pAtom = static_cast<Atom*>( pEntry->GetUserData() );
509cdf0e10cSrcweir rOutDev.SetTextColor( Color( gColors[ pAtom->getCompareStatus() ] ) );
510cdf0e10cSrcweir }
511cdf0e10cSrcweir
512cdf0e10cSrcweir SvLBoxString::Paint( rPos, rOutDev, nViewDataEntryFlags, pEntry );
513cdf0e10cSrcweir
514cdf0e10cSrcweir rOutDev.SetTextColor( aOldTextColor );
515cdf0e10cSrcweir
516cdf0e10cSrcweir /*
517cdf0e10cSrcweir Color aOldFillColor = rOutDev.GetFillColor();
518cdf0e10cSrcweir
519cdf0e10cSrcweir SvTreeListBox* pTreeBox = static_cast< SvTreeListBox* >( &rOutDev );
520cdf0e10cSrcweir long nX = pTreeBox->GetSizePixel().Width();
521cdf0e10cSrcweir
522cdf0e10cSrcweir ScrollBar* pVScroll = pTreeBox->GetVScroll();
523cdf0e10cSrcweir if ( pVScroll->IsVisible() )
524cdf0e10cSrcweir {
525cdf0e10cSrcweir nX -= pVScroll->GetSizePixel().Width();
526cdf0e10cSrcweir }
527cdf0e10cSrcweir
528cdf0e10cSrcweir SvViewDataItem* pItem = rOutDev.GetViewDataItem( pEntry, this );
529cdf0e10cSrcweir nX -= pItem->aSize.Height();
530cdf0e10cSrcweir
531cdf0e10cSrcweir long nSize = pItem->aSize.Height() / 2;
532cdf0e10cSrcweir long nHalfSize = nSize / 2;
533cdf0e10cSrcweir long nY = rPos.Y() + nHalfSize;
534cdf0e10cSrcweir
535cdf0e10cSrcweir if ( aOldFillColor == COL_WHITE )
536cdf0e10cSrcweir {
537cdf0e10cSrcweir rOutDev.SetFillColor( Color( COL_BLACK ) );
538cdf0e10cSrcweir }
539cdf0e10cSrcweir else
540cdf0e10cSrcweir {
541cdf0e10cSrcweir rOutDev.SetFillColor( Color( COL_WHITE ) );
542cdf0e10cSrcweir }
543cdf0e10cSrcweir
544cdf0e10cSrcweir long n = 0;
545cdf0e10cSrcweir while ( n <= nHalfSize )
546cdf0e10cSrcweir {
547cdf0e10cSrcweir rOutDev.DrawRect( Rectangle( nX+n, nY+n, nX+n, nY+nSize-n ) );
548cdf0e10cSrcweir n++;
549cdf0e10cSrcweir }
550cdf0e10cSrcweir
551cdf0e10cSrcweir rOutDev.SetFillColor( aOldFillColor );
552cdf0e10cSrcweir */
553cdf0e10cSrcweir }
554cdf0e10cSrcweir
555cdf0e10cSrcweir private:
556cdf0e10cSrcweir Image* mpImage;
557cdf0e10cSrcweir };
558cdf0e10cSrcweir
559cdf0e10cSrcweir
560cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
561cdf0e10cSrcweir
562cdf0e10cSrcweir class AtomContainerTreeListBox : public SvTreeListBox
563cdf0e10cSrcweir {
564cdf0e10cSrcweir public:
565cdf0e10cSrcweir AtomContainerTreeListBox( Window* pParent );
566cdf0e10cSrcweir ~AtomContainerTreeListBox();
567cdf0e10cSrcweir
568cdf0e10cSrcweir void SetRootAtom( const Atom* pAtom );
569cdf0e10cSrcweir
570cdf0e10cSrcweir
SetCollapsingHdl(const Link & rNewHdl)571cdf0e10cSrcweir void SetCollapsingHdl(const Link& rNewHdl){maCollapsingHdl=rNewHdl;}
GetCollapsingHdl() const572cdf0e10cSrcweir const Link& GetCollapsingHdl() const { return maCollapsingHdl; }
573cdf0e10cSrcweir
SetExpandingHdl(const Link & rNewHdl)574cdf0e10cSrcweir void SetExpandingHdl(const Link& rNewHdl){maExpandingHdl=rNewHdl;}
GetExpandingHdl() const575cdf0e10cSrcweir const Link& GetExpandingHdl() const { return maExpandingHdl; }
576cdf0e10cSrcweir
577cdf0e10cSrcweir virtual BOOL Expand( SvLBoxEntry* pParent );
578cdf0e10cSrcweir virtual BOOL Collapse( SvLBoxEntry* pParent );
579cdf0e10cSrcweir
580cdf0e10cSrcweir SvLBoxEntry* findAtom( Atom* pAtom );
581cdf0e10cSrcweir
582cdf0e10cSrcweir virtual void InitEntry(SvLBoxEntry*,const XubString&,const Image&,const Image&);
583cdf0e10cSrcweir virtual void SetTabs();
584cdf0e10cSrcweir
585cdf0e10cSrcweir private:
586cdf0e10cSrcweir void InsertAtom( const Atom* pAtom, SvLBoxEntry* pParent = 0 );
587cdf0e10cSrcweir const Atom* mpRootAtom;
588cdf0e10cSrcweir ResMgr* mpResMgr;
589cdf0e10cSrcweir Image maImgFolder;
590cdf0e10cSrcweir Image maImgAtom;
591cdf0e10cSrcweir Image maImgExpanded;
592cdf0e10cSrcweir Image maImgCollapsed;
593cdf0e10cSrcweir bool mbRecursiveGuard;
594cdf0e10cSrcweir Link maCollapsingHdl;
595cdf0e10cSrcweir Link maExpandingHdl;
596cdf0e10cSrcweir };
597cdf0e10cSrcweir
598cdf0e10cSrcweir typedef std::pair< AtomContainerTreeListBox*, SvLBoxEntry* > AtomContainerEntryPair;
599cdf0e10cSrcweir
AtomContainerTreeListBox(Window * pParent)600cdf0e10cSrcweir AtomContainerTreeListBox::AtomContainerTreeListBox( Window* pParent )
601cdf0e10cSrcweir : SvTreeListBox( pParent, WB_HASBUTTONS|WB_HASLINES|WB_HASBUTTONSATROOT|WB_3DLOOK|WB_BORDER ),
602cdf0e10cSrcweir mpRootAtom( 0 ), mbRecursiveGuard( false )
603cdf0e10cSrcweir {
604cdf0e10cSrcweir mpResMgr = ResMgr::CreateResMgr( "svt" );
605cdf0e10cSrcweir maImgCollapsed = Image( ResId( RID_IMG_TREENODE_COLLAPSED, mpResMgr ) );
606cdf0e10cSrcweir maImgExpanded = Image( ResId( RID_IMG_TREENODE_EXPANDED, mpResMgr ) );
607cdf0e10cSrcweir
608cdf0e10cSrcweir // SetDefaultExpandedEntryBmp( aExpanded );
609cdf0e10cSrcweir // SetDefaultCollapsedEntryBmp(aCollapsed );
610cdf0e10cSrcweir
611cdf0e10cSrcweir maImgFolder = Image( ResId( IMG_SVT_FOLDER, mpResMgr ) );
612cdf0e10cSrcweir maImgAtom = Image( ResId( IMG_SVT_DOCTEMPLATE_DOCINFO_SMALL, mpResMgr ) );
613cdf0e10cSrcweir }
614cdf0e10cSrcweir
~AtomContainerTreeListBox()615cdf0e10cSrcweir AtomContainerTreeListBox::~AtomContainerTreeListBox()
616cdf0e10cSrcweir {
617cdf0e10cSrcweir }
618cdf0e10cSrcweir
SetTabs()619cdf0e10cSrcweir void AtomContainerTreeListBox::SetTabs()
620cdf0e10cSrcweir {
621cdf0e10cSrcweir if( IsEditingActive() )
622cdf0e10cSrcweir EndEditing( TRUE );
623cdf0e10cSrcweir
624cdf0e10cSrcweir ClearTabList();
625cdf0e10cSrcweir
626cdf0e10cSrcweir short nIndent = 0; GetIndent();
627cdf0e10cSrcweir long nNodeWidthPixel = maImgCollapsed.GetSizePixel().Width();
628cdf0e10cSrcweir long nContextWidthDIV2 = nNodeWidthPixel >> 1;
629cdf0e10cSrcweir
630cdf0e10cSrcweir long nStartPos = 2 + ( nIndent + nContextWidthDIV2 );
631cdf0e10cSrcweir AddTab( nStartPos, SV_LBOXTAB_DYNAMIC | SV_LBOXTAB_ADJUST_CENTER );
632cdf0e10cSrcweir nStartPos += nNodeWidthPixel + 5;
633cdf0e10cSrcweir AddTab( nStartPos, SV_LBOXTAB_DYNAMIC | SV_LBOXTAB_ADJUST_CENTER | SV_LBOXTAB_SHOW_SELECTION );
634cdf0e10cSrcweir nStartPos += nContextWidthDIV2 + 5;
635cdf0e10cSrcweir AddTab( nStartPos, SV_LBOXTAB_DYNAMIC|SV_LBOXTAB_ADJUST_LEFT | SV_LBOXTAB_SHOW_SELECTION );
636cdf0e10cSrcweir }
637cdf0e10cSrcweir
InitEntry(SvLBoxEntry * pEntry,const XubString & aStr,const Image & aCollEntryBmp,const Image & aExpEntryBmp)638cdf0e10cSrcweir void AtomContainerTreeListBox::InitEntry(SvLBoxEntry* pEntry,const XubString& aStr,const Image& aCollEntryBmp,const Image& aExpEntryBmp)
639cdf0e10cSrcweir {
640cdf0e10cSrcweir pEntry->AddItem( new SvLBoxContextBmp( pEntry,0, aCollEntryBmp,aExpEntryBmp, SVLISTENTRYFLAG_EXPANDED ) );
641cdf0e10cSrcweir pEntry->AddItem( new SvLBoxContextBmp( pEntry,0, maImgAtom, maImgAtom, SVLISTENTRYFLAG_EXPANDED ) );
642cdf0e10cSrcweir pEntry->AddItem( new AtomBoxString( pEntry, aStr ) );
643cdf0e10cSrcweir }
644cdf0e10cSrcweir
findAtom(Atom * pAtom)645cdf0e10cSrcweir SvLBoxEntry* AtomContainerTreeListBox::findAtom( Atom* pAtom )
646cdf0e10cSrcweir {
647cdf0e10cSrcweir SvLBoxEntry* pEntry = First();
648cdf0e10cSrcweir while( pEntry )
649cdf0e10cSrcweir {
650cdf0e10cSrcweir if( pEntry->GetUserData() == pAtom )
651cdf0e10cSrcweir return pEntry;
652cdf0e10cSrcweir
653cdf0e10cSrcweir pEntry = Next( pEntry );
654cdf0e10cSrcweir }
655cdf0e10cSrcweir
656cdf0e10cSrcweir return 0;
657cdf0e10cSrcweir }
658cdf0e10cSrcweir
Expand(SvLBoxEntry * pParent)659cdf0e10cSrcweir BOOL AtomContainerTreeListBox::Expand( SvLBoxEntry* pParent )
660cdf0e10cSrcweir {
661cdf0e10cSrcweir BOOL bRet = FALSE;
662cdf0e10cSrcweir if( !mbRecursiveGuard )
663cdf0e10cSrcweir {
664cdf0e10cSrcweir mbRecursiveGuard = true;
665cdf0e10cSrcweir AtomContainerEntryPair aPair( this, pParent );
666cdf0e10cSrcweir maExpandingHdl.Call( &aPair);
667cdf0e10cSrcweir
668cdf0e10cSrcweir bRet = SvTreeListBox::Expand( pParent );
669cdf0e10cSrcweir mbRecursiveGuard = false;
670cdf0e10cSrcweir }
671cdf0e10cSrcweir return bRet;
672cdf0e10cSrcweir }
673cdf0e10cSrcweir
Collapse(SvLBoxEntry * pParent)674cdf0e10cSrcweir BOOL AtomContainerTreeListBox::Collapse( SvLBoxEntry* pParent )
675cdf0e10cSrcweir {
676cdf0e10cSrcweir BOOL bRet = FALSE;
677cdf0e10cSrcweir if( !mbRecursiveGuard )
678cdf0e10cSrcweir {
679cdf0e10cSrcweir mbRecursiveGuard = true;
680cdf0e10cSrcweir AtomContainerEntryPair aPair( this, pParent );
681cdf0e10cSrcweir maCollapsingHdl.Call( &aPair);
682cdf0e10cSrcweir
683cdf0e10cSrcweir bRet = SvTreeListBox::Collapse( pParent );
684cdf0e10cSrcweir mbRecursiveGuard = false;
685cdf0e10cSrcweir }
686cdf0e10cSrcweir return bRet;
687cdf0e10cSrcweir }
688cdf0e10cSrcweir
SetRootAtom(const Atom * pAtom)689cdf0e10cSrcweir void AtomContainerTreeListBox::SetRootAtom( const Atom* pAtom )
690cdf0e10cSrcweir {
691cdf0e10cSrcweir mpRootAtom = pAtom;
692cdf0e10cSrcweir InsertAtom( mpRootAtom );
693cdf0e10cSrcweir }
694cdf0e10cSrcweir
InsertAtom(const Atom * pAtom,SvLBoxEntry * pParent)695cdf0e10cSrcweir void AtomContainerTreeListBox::InsertAtom( const Atom* pAtom, SvLBoxEntry* pParent /* = 0 */ )
696cdf0e10cSrcweir {
697cdf0e10cSrcweir if( pAtom )
698cdf0e10cSrcweir {
699cdf0e10cSrcweir const DffRecordHeader& rHeader = pAtom->getHeader();
700cdf0e10cSrcweir
701cdf0e10cSrcweir char buffer[1024];
702cdf0e10cSrcweir
703cdf0e10cSrcweir rtl::OUString aText;
704cdf0e10cSrcweir AtomConfig* pAtomConfig = dynamic_cast< AtomConfig*>( gAtomConfigMap[rHeader.nRecType].get() );
705cdf0e10cSrcweir
706cdf0e10cSrcweir if( pAtomConfig )
707cdf0e10cSrcweir aText = pAtomConfig->getName();
708cdf0e10cSrcweir
709cdf0e10cSrcweir if( !aText.getLength() )
710cdf0e10cSrcweir {
711cdf0e10cSrcweir sprintf( buffer, "unknown_0x%04x", rHeader.nRecType );
712cdf0e10cSrcweir aText += rtl::OUString::createFromAscii( buffer );
713cdf0e10cSrcweir }
714cdf0e10cSrcweir
715cdf0e10cSrcweir sprintf( buffer, " (I: %lu L: %lu)", (UINT32)rHeader.nRecVer, (UINT32)rHeader.nRecLen );
716cdf0e10cSrcweir aText += String( rtl::OUString::createFromAscii( buffer ) );
717cdf0e10cSrcweir
718cdf0e10cSrcweir SvLBoxEntry* pEntry = 0;
719cdf0e10cSrcweir if( pAtom->isContainer() && pAtom->findFirstChildAtom() )
720cdf0e10cSrcweir {
721cdf0e10cSrcweir pEntry = InsertEntry( aText, maImgExpanded, maImgCollapsed, pParent );
722cdf0e10cSrcweir
723cdf0e10cSrcweir /** returns the first child atom or NULL */
724cdf0e10cSrcweir const Atom* pChildAtom = pAtom->findFirstChildAtom();
725cdf0e10cSrcweir
726cdf0e10cSrcweir while( pChildAtom )
727cdf0e10cSrcweir {
728cdf0e10cSrcweir InsertAtom( pChildAtom, pEntry );
729cdf0e10cSrcweir pChildAtom = pAtom->findNextChildAtom( pChildAtom );
730cdf0e10cSrcweir }
731cdf0e10cSrcweir }
732cdf0e10cSrcweir else
733cdf0e10cSrcweir {
734cdf0e10cSrcweir pEntry = InsertEntry( aText, pParent );
735cdf0e10cSrcweir }
736cdf0e10cSrcweir
737cdf0e10cSrcweir if( pEntry )
738cdf0e10cSrcweir {
739cdf0e10cSrcweir pEntry->SetUserData( (void*)pAtom );
740cdf0e10cSrcweir
741cdf0e10cSrcweir if( pAtom->isContainer() )
742cdf0e10cSrcweir {
743cdf0e10cSrcweir SvLBoxContextBmp* pBoxBmp = dynamic_cast< SvLBoxContextBmp* >( pEntry->GetItem( pEntry->ItemCount() - 2 ) );
744cdf0e10cSrcweir if( pBoxBmp )
745cdf0e10cSrcweir {
746cdf0e10cSrcweir pBoxBmp->SetBitmap1( pEntry, maImgFolder );
747cdf0e10cSrcweir pBoxBmp->SetBitmap2( pEntry, maImgFolder );
748cdf0e10cSrcweir }
749cdf0e10cSrcweir }
750cdf0e10cSrcweir
751cdf0e10cSrcweir /*
752cdf0e10cSrcweir pEntry->ReplaceItem(
753cdf0e10cSrcweir new AtomBoxString( pEntry, aText, pImage ),
754cdf0e10cSrcweir pEntry->ItemCount() - 1 );
755cdf0e10cSrcweir */
756cdf0e10cSrcweir }
757cdf0e10cSrcweir }
758cdf0e10cSrcweir }
759cdf0e10cSrcweir
760cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
761cdf0e10cSrcweir
762cdf0e10cSrcweir extern void load_config( const OUString& rPath );
763cdf0e10cSrcweir
764cdf0e10cSrcweir class PPTDocument
765cdf0e10cSrcweir {
766cdf0e10cSrcweir public:
767cdf0e10cSrcweir PPTDocument( const rtl::OUString& rFilePath );
768cdf0e10cSrcweir ~PPTDocument();
769cdf0e10cSrcweir
770cdf0e10cSrcweir Atom* getRootAtom() const;
771cdf0e10cSrcweir
772cdf0e10cSrcweir private:
773cdf0e10cSrcweir void Load( const rtl::OUString& rFilePath );
774cdf0e10cSrcweir
775cdf0e10cSrcweir Atom* mpAtom;
776cdf0e10cSrcweir SvStream* mpDocStream;
777cdf0e10cSrcweir SotStorageRef maStorage;
778cdf0e10cSrcweir };
779cdf0e10cSrcweir
780cdf0e10cSrcweir typedef boost::shared_ptr< PPTDocument > PPTDocumentPtr;
781cdf0e10cSrcweir
PPTDocument(const rtl::OUString & rFilePath)782cdf0e10cSrcweir PPTDocument::PPTDocument(const rtl::OUString& rFilePath)
783cdf0e10cSrcweir : mpAtom(0), mpDocStream(0)
784cdf0e10cSrcweir {
785cdf0e10cSrcweir Load( rFilePath );
786cdf0e10cSrcweir }
787cdf0e10cSrcweir
~PPTDocument()788cdf0e10cSrcweir PPTDocument::~PPTDocument()
789cdf0e10cSrcweir {
790cdf0e10cSrcweir delete mpAtom;
791cdf0e10cSrcweir delete mpDocStream;
792cdf0e10cSrcweir }
793cdf0e10cSrcweir
Load(const rtl::OUString & rFilePath)794cdf0e10cSrcweir void PPTDocument::Load( const rtl::OUString& rFilePath )
795cdf0e10cSrcweir {
796cdf0e10cSrcweir maStorage = new SotStorage( rFilePath, STREAM_STD_READ );
797cdf0e10cSrcweir if( !maStorage->GetError() )
798cdf0e10cSrcweir {
799cdf0e10cSrcweir mpDocStream = maStorage->OpenSotStream( String( RTL_CONSTASCII_USTRINGPARAM("PowerPoint Document") ), STREAM_STD_READ );
800cdf0e10cSrcweir if( mpDocStream )
801cdf0e10cSrcweir {
802cdf0e10cSrcweir DffRecordHeader aRecordHeader;
803cdf0e10cSrcweir *mpDocStream >> aRecordHeader;
804cdf0e10cSrcweir
805cdf0e10cSrcweir mpAtom = Atom::import( 65530, *mpDocStream );
806cdf0e10cSrcweir }
807cdf0e10cSrcweir }
808cdf0e10cSrcweir }
809cdf0e10cSrcweir
getRootAtom() const810cdf0e10cSrcweir Atom* PPTDocument::getRootAtom() const
811cdf0e10cSrcweir {
812cdf0e10cSrcweir return mpAtom;
813cdf0e10cSrcweir }
814cdf0e10cSrcweir
815cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////
816cdf0e10cSrcweir
817cdf0e10cSrcweir class MSViewerWorkWindow : public WorkWindow
818cdf0e10cSrcweir {
819cdf0e10cSrcweir public:
820cdf0e10cSrcweir MSViewerWorkWindow();
821cdf0e10cSrcweir ~MSViewerWorkWindow();
822cdf0e10cSrcweir
823cdf0e10cSrcweir PPTDocumentPtr Load();
824cdf0e10cSrcweir void onView();
825cdf0e10cSrcweir void onCompare();
826cdf0e10cSrcweir void onClose();
827cdf0e10cSrcweir
828cdf0e10cSrcweir void View( const PPTDocumentPtr& pDocument, int nPane );
829cdf0e10cSrcweir void Compare( const PPTDocumentPtr& pDocument1, const PPTDocumentPtr& pDocument2 );
830cdf0e10cSrcweir
831cdf0e10cSrcweir virtual void Resize();
832cdf0e10cSrcweir
833cdf0e10cSrcweir private:
834cdf0e10cSrcweir void Sync( AtomContainerEntryPair* pPair, int nAction );
835cdf0e10cSrcweir
836cdf0e10cSrcweir AtomContainerTreeListBox* mpListBox[2];
837cdf0e10cSrcweir MultiLineEdit* mpEdit[2];
838cdf0e10cSrcweir PPTDocumentPtr mpDocument[2];
839cdf0e10cSrcweir MenuBar* mpMenuBar;
840cdf0e10cSrcweir PopupMenu* mpFileMenu;
841cdf0e10cSrcweir bool mbSelectHdlGuard;
842cdf0e10cSrcweir DECL_LINK( implSelectHdl, AtomContainerTreeListBox* );
843cdf0e10cSrcweir DECL_LINK( implExpandingHdl, AtomContainerEntryPair* );
844cdf0e10cSrcweir DECL_LINK( implCollapsingHdl, AtomContainerEntryPair* );
845cdf0e10cSrcweir DECL_LINK( implMenuHdl, Menu* );
846cdf0e10cSrcweir };
847cdf0e10cSrcweir
848cdf0e10cSrcweir // -----------------------------------------------------------------------
849cdf0e10cSrcweir
onView()850cdf0e10cSrcweir void MSViewerWorkWindow::onView()
851cdf0e10cSrcweir {
852cdf0e10cSrcweir PPTDocumentPtr pDocument( Load() );
853cdf0e10cSrcweir if( pDocument.get() )
854cdf0e10cSrcweir {
855cdf0e10cSrcweir onClose();
856cdf0e10cSrcweir View( pDocument, 0 );
857cdf0e10cSrcweir }
858cdf0e10cSrcweir }
859cdf0e10cSrcweir
onClose()860cdf0e10cSrcweir void MSViewerWorkWindow::onClose()
861cdf0e10cSrcweir {
862cdf0e10cSrcweir }
863cdf0e10cSrcweir
onCompare()864cdf0e10cSrcweir void MSViewerWorkWindow::onCompare()
865cdf0e10cSrcweir {
866cdf0e10cSrcweir PPTDocumentPtr pDocument1( Load() );
867cdf0e10cSrcweir if( pDocument1.get() )
868cdf0e10cSrcweir {
869cdf0e10cSrcweir PPTDocumentPtr pDocument2( Load() );
870cdf0e10cSrcweir if( pDocument2.get() )
871cdf0e10cSrcweir {
872cdf0e10cSrcweir onClose();
873cdf0e10cSrcweir Compare( pDocument1, pDocument2 );
874cdf0e10cSrcweir }
875cdf0e10cSrcweir }
876cdf0e10cSrcweir }
877cdf0e10cSrcweir
Compare(const PPTDocumentPtr & pDocument1,const PPTDocumentPtr & pDocument2)878cdf0e10cSrcweir void MSViewerWorkWindow::Compare( const PPTDocumentPtr& pDocument1, const PPTDocumentPtr& pDocument2 )
879cdf0e10cSrcweir {
880cdf0e10cSrcweir if( pDocument1.get() && pDocument2.get() )
881cdf0e10cSrcweir {
882cdf0e10cSrcweir Atom* pAtom1 = pDocument1->getRootAtom();
883cdf0e10cSrcweir Atom* pAtom2 = pDocument2->getRootAtom();
884cdf0e10cSrcweir pAtom1->setCompareAtom( pAtom2 );
885cdf0e10cSrcweir pAtom2->setCompareAtom( pAtom1 );
886cdf0e10cSrcweir }
887cdf0e10cSrcweir
888cdf0e10cSrcweir View( pDocument1, 0 );
889cdf0e10cSrcweir View( pDocument2, 1 );
890cdf0e10cSrcweir }
891cdf0e10cSrcweir
View(const PPTDocumentPtr & pDocument,int nPane)892cdf0e10cSrcweir void MSViewerWorkWindow::View( const PPTDocumentPtr& pDocument, int nPane )
893cdf0e10cSrcweir {
894cdf0e10cSrcweir if( ((nPane != 0) && (nPane != 1)) || (pDocument.get() == 0) )
895cdf0e10cSrcweir return;
896cdf0e10cSrcweir
897cdf0e10cSrcweir mpDocument[nPane] = pDocument;
898cdf0e10cSrcweir
899cdf0e10cSrcweir mpListBox[nPane]->SetRootAtom( pDocument->getRootAtom() );
900cdf0e10cSrcweir mpListBox[nPane]->Expand( mpListBox[nPane]->GetEntry(0) );
901cdf0e10cSrcweir mpListBox[nPane]->Show();
902cdf0e10cSrcweir mpEdit[nPane]->Show();
903cdf0e10cSrcweir Resize();
904cdf0e10cSrcweir }
905cdf0e10cSrcweir
906cdf0e10cSrcweir
Load()907cdf0e10cSrcweir PPTDocumentPtr MSViewerWorkWindow::Load()
908cdf0e10cSrcweir {
909cdf0e10cSrcweir ::sfx2::FileDialogHelper aDlg( ::sfx2::FILEOPEN_SIMPLE, 0 );
910cdf0e10cSrcweir String aStrFilterType( RTL_CONSTASCII_USTRINGPARAM( "*.ppt" ) );
911cdf0e10cSrcweir aDlg.AddFilter( aStrFilterType, aStrFilterType );
912cdf0e10cSrcweir // INetURLObject aFile( SvtPathOptions().GetPalettePath() );
913cdf0e10cSrcweir // aDlg.SetDisplayDirectory( aFile.GetMainURL( INetURLObject::NO_DECODE ) );
914cdf0e10cSrcweir
915cdf0e10cSrcweir PPTDocumentPtr pDocument;
916cdf0e10cSrcweir if ( aDlg.Execute() == ERRCODE_NONE )
917cdf0e10cSrcweir {
918cdf0e10cSrcweir pDocument.reset( new PPTDocument( aDlg.GetPath() ) );
919cdf0e10cSrcweir }
920cdf0e10cSrcweir
921cdf0e10cSrcweir return pDocument;
922cdf0e10cSrcweir }
923cdf0e10cSrcweir
924cdf0e10cSrcweir // -----------------------------------------------------------------------
925cdf0e10cSrcweir
MSViewerWorkWindow()926cdf0e10cSrcweir MSViewerWorkWindow::MSViewerWorkWindow() :
927cdf0e10cSrcweir WorkWindow( 0, WB_APP | WB_STDWORK | WB_3DLOOK ),mbSelectHdlGuard(false)
928cdf0e10cSrcweir {
929cdf0e10cSrcweir Size aOutputSize( 400, 600 );
930cdf0e10cSrcweir SetOutputSizePixel( aOutputSize );
931cdf0e10cSrcweir SetText( String( RTL_CONSTASCII_USTRINGPARAM( "MSViewer" ) ) );
932cdf0e10cSrcweir
933cdf0e10cSrcweir Size aOutSize( GetOutputSizePixel() );
934cdf0e10cSrcweir
935cdf0e10cSrcweir Font aFont( String( RTL_CONSTASCII_USTRINGPARAM( "Courier" ) ), GetFont().GetSize() );
936cdf0e10cSrcweir
937cdf0e10cSrcweir mpMenuBar = new MenuBar();
938cdf0e10cSrcweir mpMenuBar->InsertItem( 1, String( RTL_CONSTASCII_USTRINGPARAM("~File" ) ) );
939cdf0e10cSrcweir mpFileMenu = new PopupMenu();
940cdf0e10cSrcweir mpFileMenu->InsertItem( 2, String( RTL_CONSTASCII_USTRINGPARAM("~View" ) ) );
941cdf0e10cSrcweir mpFileMenu->InsertItem( 3, String( RTL_CONSTASCII_USTRINGPARAM("~Compare" ) ) );
942cdf0e10cSrcweir mpFileMenu->InsertSeparator();
943cdf0e10cSrcweir mpFileMenu->InsertItem( 4, String( RTL_CONSTASCII_USTRINGPARAM("~Quit" ) ) );
944cdf0e10cSrcweir mpFileMenu->SetSelectHdl( LINK( this, MSViewerWorkWindow, implMenuHdl ) );
945cdf0e10cSrcweir
946cdf0e10cSrcweir mpMenuBar->SetPopupMenu( 1, mpFileMenu );
947cdf0e10cSrcweir SetMenuBar( mpMenuBar );
948cdf0e10cSrcweir int nPane;
949cdf0e10cSrcweir for( nPane = 0; nPane < 2; nPane++ )
950cdf0e10cSrcweir {
951cdf0e10cSrcweir mpListBox[nPane] = new AtomContainerTreeListBox( this );
952cdf0e10cSrcweir mpListBox[nPane]->SetSelectHdl( LINK( this, MSViewerWorkWindow, implSelectHdl ) );
953cdf0e10cSrcweir mpListBox[nPane]->SetExpandingHdl( LINK( this, MSViewerWorkWindow, implExpandingHdl ) );
954cdf0e10cSrcweir mpListBox[nPane]->SetCollapsingHdl( LINK( this, MSViewerWorkWindow, implCollapsingHdl ) );
955cdf0e10cSrcweir
956cdf0e10cSrcweir mpEdit[nPane] = new MultiLineEdit(this, WB_3DLOOK | WB_BORDER | WB_LEFT | WB_TOP | WB_READONLY | WB_HSCROLL | WB_VSCROLL );
957cdf0e10cSrcweir mpEdit[nPane]->SetReadOnly( TRUE );
958cdf0e10cSrcweir mpEdit[nPane]->SetReadOnly( TRUE );
959cdf0e10cSrcweir mpEdit[nPane]->SetControlFont( aFont );
960cdf0e10cSrcweir }
961cdf0e10cSrcweir }
962cdf0e10cSrcweir
963cdf0e10cSrcweir // -----------------------------------------------------------------------
964cdf0e10cSrcweir
GetAtomText(const Atom * pAtom)965cdf0e10cSrcweir static String GetAtomText( const Atom* pAtom )
966cdf0e10cSrcweir {
967cdf0e10cSrcweir String aText;
968cdf0e10cSrcweir if( pAtom )
969cdf0e10cSrcweir {
970cdf0e10cSrcweir const DffRecordHeader& rHeader = pAtom->getHeader();
971cdf0e10cSrcweir char buffer[512];
972cdf0e10cSrcweir sprintf( buffer, "Version = %lu\n\rInstance = %lu\n\rVersionInstance = %lu\n\rLength = %lu\n\r",
973cdf0e10cSrcweir (UINT32)rHeader.nRecVer,
974cdf0e10cSrcweir (UINT32)rHeader.nRecInstance,
975cdf0e10cSrcweir (UINT32)rHeader.nImpVerInst,
976cdf0e10cSrcweir (UINT32)rHeader.nRecLen );
977cdf0e10cSrcweir aText = rtl::OUString::createFromAscii( buffer );
978cdf0e10cSrcweir if( pAtom->isContainer() )
979cdf0e10cSrcweir {
980cdf0e10cSrcweir
981cdf0e10cSrcweir }
982cdf0e10cSrcweir else
983cdf0e10cSrcweir {
984cdf0e10cSrcweir pAtom->seekToContent();
985cdf0e10cSrcweir AtomConfig* pAtomConfig = dynamic_cast< AtomConfig* >( gAtomConfigMap[pAtom->getType()].get() );
986cdf0e10cSrcweir if( pAtomConfig )
987cdf0e10cSrcweir {
988cdf0e10cSrcweir sal_Size nLength = pAtom->getLength();
989cdf0e10cSrcweir aText += String( pAtomConfig->format( pAtom->getStream(), nLength ) );
990cdf0e10cSrcweir }
991cdf0e10cSrcweir else
992cdf0e10cSrcweir {
993cdf0e10cSrcweir sal_Size nLength = pAtom->getLength();
994cdf0e10cSrcweir aText += String( ElementConfig::dump_hex( pAtom->getStream(), nLength ) );
995cdf0e10cSrcweir }
996cdf0e10cSrcweir }
997cdf0e10cSrcweir }
998cdf0e10cSrcweir
999cdf0e10cSrcweir return aText;
1000cdf0e10cSrcweir }
1001cdf0e10cSrcweir
IMPL_LINK(MSViewerWorkWindow,implSelectHdl,AtomContainerTreeListBox *,pListBox)1002cdf0e10cSrcweir IMPL_LINK(MSViewerWorkWindow,implSelectHdl, AtomContainerTreeListBox*, pListBox )
1003cdf0e10cSrcweir {
1004cdf0e10cSrcweir int nPane = (pListBox == mpListBox[1]) ? 1 : 0;
1005cdf0e10cSrcweir SvLBoxEntry* pEntry = mpListBox[nPane]->FirstSelected();
1006cdf0e10cSrcweir if( pEntry && pEntry->GetUserData() )
1007cdf0e10cSrcweir {
1008cdf0e10cSrcweir Atom* pAtom = static_cast<Atom*>( pEntry->GetUserData() );
1009cdf0e10cSrcweir mpEdit[nPane]->SetText( GetAtomText( pAtom ) );
1010cdf0e10cSrcweir
1011cdf0e10cSrcweir if(!mbSelectHdlGuard)
1012cdf0e10cSrcweir {
1013cdf0e10cSrcweir mbSelectHdlGuard = true;
1014cdf0e10cSrcweir // select other
1015cdf0e10cSrcweir AtomContainerEntryPair aPair( pListBox, pEntry );
1016cdf0e10cSrcweir Sync( &aPair, 2 );
1017cdf0e10cSrcweir mbSelectHdlGuard = false;
1018cdf0e10cSrcweir }
1019cdf0e10cSrcweir }
1020cdf0e10cSrcweir return 0;
1021cdf0e10cSrcweir }
1022cdf0e10cSrcweir
Sync(AtomContainerEntryPair * pPair,int nAction)1023cdf0e10cSrcweir void MSViewerWorkWindow::Sync( AtomContainerEntryPair* pPair, int nAction )
1024cdf0e10cSrcweir {
1025cdf0e10cSrcweir if( mpDocument[0].get() && mpDocument[1].get() && pPair->first && pPair->second )
1026cdf0e10cSrcweir {
1027cdf0e10cSrcweir AtomContainerTreeListBox* pDestinationListBox = (pPair->first == mpListBox[0]) ? mpListBox[1] : mpListBox[0];
1028cdf0e10cSrcweir
1029cdf0e10cSrcweir Atom* pAtom = static_cast<Atom*>(pPair->second->GetUserData());
1030cdf0e10cSrcweir if( pAtom && pAtom->getCompareAtom() )
1031cdf0e10cSrcweir {
1032cdf0e10cSrcweir SvLBoxEntry* pEntry = pDestinationListBox->findAtom( pAtom->getCompareAtom() );
1033cdf0e10cSrcweir
1034cdf0e10cSrcweir if(pEntry )
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir if( nAction == 0 )
1037cdf0e10cSrcweir {
1038cdf0e10cSrcweir pDestinationListBox->Expand( pEntry );
1039cdf0e10cSrcweir }
1040cdf0e10cSrcweir else if( nAction == 1 )
1041cdf0e10cSrcweir {
1042cdf0e10cSrcweir pDestinationListBox->Collapse( pEntry );
1043cdf0e10cSrcweir }
1044cdf0e10cSrcweir else
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir pDestinationListBox->Select( pEntry );
1047cdf0e10cSrcweir }
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir }
1050cdf0e10cSrcweir }
1051cdf0e10cSrcweir }
1052cdf0e10cSrcweir
IMPL_LINK(MSViewerWorkWindow,implExpandingHdl,AtomContainerEntryPair *,pPair)1053cdf0e10cSrcweir IMPL_LINK(MSViewerWorkWindow, implExpandingHdl, AtomContainerEntryPair*, pPair )
1054cdf0e10cSrcweir {
1055cdf0e10cSrcweir SvLBoxEntry* pEntry = pPair->second;
1056cdf0e10cSrcweir if( pEntry && pEntry->GetUserData() )
1057cdf0e10cSrcweir {
1058cdf0e10cSrcweir Atom* pAtom = static_cast<Atom*>( pEntry->GetUserData() );
1059cdf0e10cSrcweir pAtom->compare( pAtom->getCompareAtom() );
1060cdf0e10cSrcweir }
1061cdf0e10cSrcweir
1062cdf0e10cSrcweir Sync( pPair, 0 );
1063cdf0e10cSrcweir
1064cdf0e10cSrcweir return 0;
1065cdf0e10cSrcweir }
1066cdf0e10cSrcweir
IMPL_LINK(MSViewerWorkWindow,implCollapsingHdl,AtomContainerEntryPair *,pPair)1067cdf0e10cSrcweir IMPL_LINK(MSViewerWorkWindow, implCollapsingHdl, AtomContainerEntryPair*, pPair )
1068cdf0e10cSrcweir {
1069cdf0e10cSrcweir Sync( pPair, 1 );
1070cdf0e10cSrcweir
1071cdf0e10cSrcweir return 0;
1072cdf0e10cSrcweir }
1073cdf0e10cSrcweir
IMPL_LINK(MSViewerWorkWindow,implMenuHdl,Menu *,pMenu)1074cdf0e10cSrcweir IMPL_LINK( MSViewerWorkWindow, implMenuHdl, Menu*, pMenu )
1075cdf0e10cSrcweir {
1076cdf0e10cSrcweir if( pMenu )
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir USHORT nId = pMenu->GetCurItemId();
1079cdf0e10cSrcweir switch( nId )
1080cdf0e10cSrcweir {
1081cdf0e10cSrcweir case 2: onView(); break;
1082cdf0e10cSrcweir case 3: onCompare(); break;
1083cdf0e10cSrcweir case 4: Application::Quit(); break;
1084cdf0e10cSrcweir }
1085cdf0e10cSrcweir }
1086cdf0e10cSrcweir return 0;
1087cdf0e10cSrcweir }
1088cdf0e10cSrcweir
1089cdf0e10cSrcweir // -----------------------------------------------------------------------
1090cdf0e10cSrcweir
~MSViewerWorkWindow()1091cdf0e10cSrcweir MSViewerWorkWindow::~MSViewerWorkWindow()
1092cdf0e10cSrcweir {
1093cdf0e10cSrcweir int nPane;
1094cdf0e10cSrcweir for( nPane = 0; nPane < 2; nPane++ )
1095cdf0e10cSrcweir {
1096cdf0e10cSrcweir delete mpListBox[nPane];
1097cdf0e10cSrcweir delete mpEdit[nPane];
1098cdf0e10cSrcweir }
1099cdf0e10cSrcweir
1100cdf0e10cSrcweir delete mpFileMenu;
1101cdf0e10cSrcweir delete mpMenuBar;
1102cdf0e10cSrcweir }
1103cdf0e10cSrcweir
1104cdf0e10cSrcweir // -----------------------------------------------------------------------
1105cdf0e10cSrcweir
Resize()1106cdf0e10cSrcweir void MSViewerWorkWindow::Resize()
1107cdf0e10cSrcweir {
1108cdf0e10cSrcweir int nPaneCount = ((mpDocument[0].get() != 0) ? 1 : 0) + ((mpDocument[1].get() != 0) ? 1 : 0);
1109cdf0e10cSrcweir
1110cdf0e10cSrcweir Size aOutputSize( GetOutputSizePixel() );
1111cdf0e10cSrcweir int nHeight = aOutputSize.Height() >> 1;
1112cdf0e10cSrcweir if( nPaneCount )
1113cdf0e10cSrcweir {
1114cdf0e10cSrcweir int nWidth = aOutputSize.Width();
1115cdf0e10cSrcweir if( nPaneCount == 2 )
1116cdf0e10cSrcweir nWidth >>= 1;
1117cdf0e10cSrcweir
1118cdf0e10cSrcweir int nPosX = 0;
1119cdf0e10cSrcweir
1120cdf0e10cSrcweir int nPane;
1121cdf0e10cSrcweir for( nPane = 0; nPane < 2; nPane++ )
1122cdf0e10cSrcweir {
1123cdf0e10cSrcweir mpListBox[nPane]->SetPosSizePixel( nPosX,0, nWidth, nHeight );
1124cdf0e10cSrcweir mpEdit[nPane]->SetPosSizePixel( nPosX, nHeight, nWidth, aOutputSize.Height() - nHeight );
1125cdf0e10cSrcweir nPosX += nWidth;
1126cdf0e10cSrcweir }
1127cdf0e10cSrcweir }
1128cdf0e10cSrcweir }
1129cdf0e10cSrcweir
1130cdf0e10cSrcweir // -----------------------------------------------------------------------
1131cdf0e10cSrcweir
1132cdf0e10cSrcweir // -----------------------------------------------------------------------
1133cdf0e10cSrcweir
SAL_IMPLEMENT_MAIN()1134cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir if( argc > 3 )
1137cdf0e10cSrcweir return 0;
1138cdf0e10cSrcweir
1139cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xMSF;
1140cdf0e10cSrcweir try
1141cdf0e10cSrcweir {
1142cdf0e10cSrcweir uno::Reference< uno::XComponentContext > xCtx( cppu::defaultBootstrap_InitialComponentContext() );
1143cdf0e10cSrcweir if ( !xCtx.is() )
1144cdf0e10cSrcweir {
1145cdf0e10cSrcweir DBG_ERROR( "Error creating initial component context!" );
1146cdf0e10cSrcweir return -1;
1147cdf0e10cSrcweir }
1148cdf0e10cSrcweir
1149cdf0e10cSrcweir xMSF = uno::Reference< lang::XMultiServiceFactory >(xCtx->getServiceManager(), uno::UNO_QUERY );
1150cdf0e10cSrcweir
1151cdf0e10cSrcweir if ( !xMSF.is() )
1152cdf0e10cSrcweir {
1153cdf0e10cSrcweir DBG_ERROR( "No service manager!" );
1154cdf0e10cSrcweir return -1;
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir
1157cdf0e10cSrcweir // Init UCB
1158cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 );
1159cdf0e10cSrcweir aArgs[ 0 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL );
1160cdf0e10cSrcweir aArgs[ 1 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE );
1161cdf0e10cSrcweir sal_Bool bSuccess = ::ucb::ContentBroker::initialize( xMSF, aArgs );
1162cdf0e10cSrcweir if ( !bSuccess )
1163cdf0e10cSrcweir {
1164cdf0e10cSrcweir DBG_ERROR( "Error creating UCB!" );
1165cdf0e10cSrcweir return -1;
1166cdf0e10cSrcweir }
1167cdf0e10cSrcweir
1168cdf0e10cSrcweir }
1169cdf0e10cSrcweir catch ( uno::Exception const & )
1170cdf0e10cSrcweir {
1171cdf0e10cSrcweir DBG_ERROR( "Exception during creation of initial component context!" );
1172cdf0e10cSrcweir return -1;
1173cdf0e10cSrcweir }
1174cdf0e10cSrcweir comphelper::setProcessServiceFactory( xMSF );
1175cdf0e10cSrcweir
1176cdf0e10cSrcweir InitVCL( xMSF );
1177cdf0e10cSrcweir
1178cdf0e10cSrcweir String aConfigURL;
1179cdf0e10cSrcweir if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( Application::GetAppFileName(), aConfigURL ) )
1180cdf0e10cSrcweir {
1181cdf0e10cSrcweir INetURLObject aURL( aConfigURL );
1182cdf0e10cSrcweir
1183cdf0e10cSrcweir aURL.removeSegment();
1184cdf0e10cSrcweir aURL.removeFinalSlash();
1185cdf0e10cSrcweir aURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( "msview.xml" ) ) );
1186cdf0e10cSrcweir
1187cdf0e10cSrcweir load_config( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
1188cdf0e10cSrcweir }
1189cdf0e10cSrcweir
1190cdf0e10cSrcweir {
1191cdf0e10cSrcweir MSViewerWorkWindow aMainWindow;
1192cdf0e10cSrcweir
1193cdf0e10cSrcweir if( argc >= 2 )
1194cdf0e10cSrcweir {
1195cdf0e10cSrcweir const rtl::OUString aFile1( rtl::OUString::createFromAscii(argv[1]) );
1196cdf0e10cSrcweir PPTDocumentPtr pDocument1( new PPTDocument( aFile1 ) );
1197cdf0e10cSrcweir
1198cdf0e10cSrcweir if( argc == 3 )
1199cdf0e10cSrcweir {
1200cdf0e10cSrcweir const rtl::OUString aFile2( rtl::OUString::createFromAscii(argv[2]) );
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir PPTDocumentPtr pDocument2;
1203cdf0e10cSrcweir pDocument2.reset( new PPTDocument( aFile2 ) );
1204cdf0e10cSrcweir aMainWindow.Compare( pDocument1, pDocument2 );
1205cdf0e10cSrcweir }
1206cdf0e10cSrcweir else
1207cdf0e10cSrcweir {
1208cdf0e10cSrcweir aMainWindow.View( pDocument1, 0 );
1209cdf0e10cSrcweir }
1210cdf0e10cSrcweir }
1211cdf0e10cSrcweir
1212cdf0e10cSrcweir aMainWindow.Show();
1213cdf0e10cSrcweir
1214cdf0e10cSrcweir Application::Execute();
1215cdf0e10cSrcweir }
1216cdf0e10cSrcweir
1217cdf0e10cSrcweir DeInitVCL();
1218cdf0e10cSrcweir
1219cdf0e10cSrcweir return 0;
1220cdf0e10cSrcweir }
1221