xref: /aoo41x/main/sfx2/source/doc/objitem.cxx (revision d119d52d)
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_sfx2.hxx"
26 
27 #ifndef GCC
28 #endif
29 
30 #include <sfx2/objsh.hxx>
31 //#include "objshimp.hxx"
32 #include <sfx2/objitem.hxx>
33 #include <com/sun/star/lang/XUnoTunnel.hpp>
34 
35 //====================================================================
36 
37 TYPEINIT1_AUTOFACTORY(SfxObjectShellItem,SfxPoolItem)
38 TYPEINIT1_AUTOFACTORY(SfxObjectItem,SfxPoolItem)
39 
40 //=========================================================================
41 
42 int SfxObjectShellItem::operator==( const SfxPoolItem &rItem ) const
43 {
44 	 return PTR_CAST(SfxObjectShellItem, &rItem)->pObjSh == pObjSh;
45 }
46 
47 //--------------------------------------------------------------------
48 
GetValueText() const49 String SfxObjectShellItem::GetValueText() const
50 {
51 	return String();
52 }
53 
54 //--------------------------------------------------------------------
55 
Clone(SfxItemPool *) const56 SfxPoolItem* SfxObjectShellItem::Clone( SfxItemPool *) const
57 {
58 	return new SfxObjectShellItem( Which(), pObjSh );
59 }
60 
61 //--------------------------------------------------------------------
62 
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const63 sal_Bool SfxObjectShellItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
64 {
65     if ( pObjSh )
66     {
67         // This item MUST provide a model. Please don't change this, there are UNO-based
68         // implementations which need it!!
69         rVal <<= pObjSh->GetModel();
70     }
71     else
72     {
73         rVal <<= ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >();
74     }
75     return sal_True;
76 }
77 
78 //--------------------------------------------------------------------
79 
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)80 sal_Bool SfxObjectShellItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
81 {
82     // This item MUST have a model. Please don't change this, there are UNO-based
83     // implementations which need it!!
84     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > xModel;
85 
86     if ( rVal >>= xModel )
87     {
88         if ( xModel.is() )
89         {
90             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xTunnel(
91                 xModel, ::com::sun::star::uno::UNO_QUERY );
92             if ( xTunnel.is() )
93             {
94                 ::com::sun::star::uno::Sequence < sal_Int8 > aSeq( (sal_Int8*) SvGlobalName( SFX_GLOBAL_CLASSID ).GetBytes(), 16 );
95                 sal_Int64 nHandle = xTunnel->getSomething( aSeq );
96                 if ( nHandle )
97                 {
98                     pObjSh = reinterpret_cast< SfxObjectShell* >(sal::static_int_cast<sal_IntPtr>( nHandle ));
99                     return sal_True;
100                 }
101             }
102         }
103 
104         pObjSh = 0;
105         return sal_True;
106     }
107 
108     return sal_False;
109 }
110 
111 //=========================================================================
112 
SfxObjectItem(sal_uInt16 nWhichId,SfxShell * pSh)113 SfxObjectItem::SfxObjectItem( sal_uInt16 nWhichId, SfxShell *pSh )
114 :	SfxPoolItem( nWhichId ),
115     _pSh( pSh )
116 {}
117 
118 //--------------------------------------------------------------------
119 
operator ==(const SfxPoolItem & rItem) const120 int SfxObjectItem::operator==( const SfxPoolItem &rItem ) const
121 {
122 	 SfxObjectItem *pOther = PTR_CAST(SfxObjectItem, &rItem);
123      return pOther->_pSh == _pSh;
124 }
125 
126 //--------------------------------------------------------------------
127 
Clone(SfxItemPool *) const128 SfxPoolItem* SfxObjectItem::Clone( SfxItemPool *) const
129 {
130     return new SfxObjectItem( Which(), _pSh );
131 }
132