1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basctl.hxx"
30 
31 #include "docsignature.hxx"
32 #include "scriptdocument.hxx"
33 
34 /** === begin UNO includes === **/
35 /** === end UNO includes === **/
36 
37 #include <sfx2/objsh.hxx>
38 #include <sfx2/signaturestate.hxx>
39 
40 //........................................................................
41 namespace basctl
42 {
43 //........................................................................
44 
45 	/** === begin UNO using === **/
46 	using ::com::sun::star::uno::Reference;
47 	using ::com::sun::star::uno::UNO_QUERY;
48 	using ::com::sun::star::uno::UNO_QUERY_THROW;
49 	using ::com::sun::star::uno::Exception;
50 	using ::com::sun::star::uno::RuntimeException;
51     using ::com::sun::star::frame::XModel;
52 	/** === end UNO using === **/
53 
54 	//====================================================================
55 	//= DocumentSignature_Data
56 	//====================================================================
57     struct DocumentSignature_Data
58     {
59         SfxObjectShell*   pShell;
60 
61         DocumentSignature_Data() : pShell( NULL ) { }
62     };
63 
64 	//====================================================================
65 	//= DocumentSignature
66 	//====================================================================
67 	//--------------------------------------------------------------------
68     DocumentSignature::DocumentSignature( const ScriptDocument& _rDocument )
69         :m_pData( new DocumentSignature_Data )
70     {
71         if ( _rDocument.isDocument() )
72         {
73             Reference< XModel > xDocument( _rDocument.getDocument() );
74             // find object shell for document
75             SfxObjectShell* pShell = SfxObjectShell::GetFirst();
76             while ( pShell )
77             {
78                 if ( pShell->GetModel() == xDocument )
79                     break;
80                 pShell = SfxObjectShell::GetNext( *pShell );
81             }
82             m_pData->pShell = pShell;
83         }
84     }
85 
86 	//--------------------------------------------------------------------
87     DocumentSignature::~DocumentSignature()
88     {
89     }
90 
91 	//--------------------------------------------------------------------
92     bool DocumentSignature::supportsSignatures() const
93     {
94         return ( m_pData->pShell != NULL );
95     }
96 
97 	//--------------------------------------------------------------------
98     void DocumentSignature::signScriptingContent() const
99     {
100         OSL_PRECOND( supportsSignatures(), "DocumentSignature::signScriptingContent: signatures not supported by this document!" );
101         if ( m_pData->pShell )
102             m_pData->pShell->SignScriptingContent();
103     }
104 
105 	//--------------------------------------------------------------------
106     sal_uInt16 DocumentSignature::getScriptingSignatureState() const
107     {
108         if ( m_pData->pShell )
109             return m_pData->pShell->GetScriptingSignatureState();
110         return SIGNATURESTATE_NOSIGNATURES;
111     }
112 
113 //........................................................................
114 } // namespace basctl
115 //........................................................................
116