1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_basctl.hxx"
26 
27 #include "docsignature.hxx"
28 #include "scriptdocument.hxx"
29 
30 /** === begin UNO includes === **/
31 /** === end UNO includes === **/
32 
33 #include <sfx2/objsh.hxx>
34 #include <sfx2/signaturestate.hxx>
35 
36 //........................................................................
37 namespace basctl
38 {
39 //........................................................................
40 
41 	/** === begin UNO using === **/
42 	using ::com::sun::star::uno::Reference;
43 	using ::com::sun::star::uno::UNO_QUERY;
44 	using ::com::sun::star::uno::UNO_QUERY_THROW;
45 	using ::com::sun::star::uno::Exception;
46 	using ::com::sun::star::uno::RuntimeException;
47     using ::com::sun::star::frame::XModel;
48 	/** === end UNO using === **/
49 
50 	//====================================================================
51 	//= DocumentSignature_Data
52 	//====================================================================
53     struct DocumentSignature_Data
54     {
55         SfxObjectShell*   pShell;
56 
DocumentSignature_Databasctl::DocumentSignature_Data57         DocumentSignature_Data() : pShell( NULL ) { }
58     };
59 
60 	//====================================================================
61 	//= DocumentSignature
62 	//====================================================================
63 	//--------------------------------------------------------------------
DocumentSignature(const ScriptDocument & _rDocument)64     DocumentSignature::DocumentSignature( const ScriptDocument& _rDocument )
65         :m_pData( new DocumentSignature_Data )
66     {
67         if ( _rDocument.isDocument() )
68         {
69             Reference< XModel > xDocument( _rDocument.getDocument() );
70             // find object shell for document
71             SfxObjectShell* pShell = SfxObjectShell::GetFirst();
72             while ( pShell )
73             {
74                 if ( pShell->GetModel() == xDocument )
75                     break;
76                 pShell = SfxObjectShell::GetNext( *pShell );
77             }
78             m_pData->pShell = pShell;
79         }
80     }
81 
82 	//--------------------------------------------------------------------
~DocumentSignature()83     DocumentSignature::~DocumentSignature()
84     {
85     }
86 
87 	//--------------------------------------------------------------------
supportsSignatures() const88     bool DocumentSignature::supportsSignatures() const
89     {
90         return ( m_pData->pShell != NULL );
91     }
92 
93 	//--------------------------------------------------------------------
signScriptingContent() const94     void DocumentSignature::signScriptingContent() const
95     {
96         OSL_PRECOND( supportsSignatures(), "DocumentSignature::signScriptingContent: signatures not supported by this document!" );
97         if ( m_pData->pShell )
98             m_pData->pShell->SignScriptingContent();
99     }
100 
101 	//--------------------------------------------------------------------
getScriptingSignatureState() const102     sal_uInt16 DocumentSignature::getScriptingSignatureState() const
103     {
104         if ( m_pData->pShell )
105             return m_pData->pShell->GetScriptingSignatureState();
106         return SIGNATURESTATE_NOSIGNATURES;
107     }
108 
109 //........................................................................
110 } // namespace basctl
111 //........................................................................
112