Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / doc / objitem.cxx
blob658f5b825ef76ea35547996e3fdee1e19344f1b6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <sfx2/objsh.hxx>
31 #include <sfx2/objitem.hxx>
32 #include <com/sun/star/lang/XUnoTunnel.hpp>
34 //====================================================================
36 TYPEINIT1_AUTOFACTORY(SfxObjectShellItem,SfxPoolItem)
37 TYPEINIT1_AUTOFACTORY(SfxObjectItem,SfxPoolItem)
39 //=========================================================================
41 int SfxObjectShellItem::operator==( const SfxPoolItem &rItem ) const
43 return PTR_CAST(SfxObjectShellItem, &rItem)->pObjSh == pObjSh;
46 //--------------------------------------------------------------------
48 String SfxObjectShellItem::GetValueText() const
50 return String();
53 //--------------------------------------------------------------------
55 SfxPoolItem* SfxObjectShellItem::Clone( SfxItemPool *) const
57 return new SfxObjectShellItem( Which(), pObjSh );
60 //--------------------------------------------------------------------
62 bool SfxObjectShellItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
64 if ( pObjSh )
66 // This item MUST provide a model. Please don't change this, there are UNO-based
67 // implementations which need it!!
68 rVal <<= pObjSh->GetModel();
70 else
72 rVal <<= ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >();
74 return true;
77 //--------------------------------------------------------------------
79 bool SfxObjectShellItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
81 // This item MUST have a model. Please don't change this, there are UNO-based
82 // implementations which need it!!
83 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > xModel;
85 if ( rVal >>= xModel )
87 if ( xModel.is() )
89 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xTunnel(
90 xModel, ::com::sun::star::uno::UNO_QUERY );
91 if ( xTunnel.is() )
93 ::com::sun::star::uno::Sequence < sal_Int8 > aSeq( (sal_Int8*) SvGlobalName( SFX_GLOBAL_CLASSID ).GetBytes(), 16 );
94 sal_Int64 nHandle = xTunnel->getSomething( aSeq );
95 if ( nHandle )
97 pObjSh = reinterpret_cast< SfxObjectShell* >(sal::static_int_cast<sal_IntPtr>( nHandle ));
98 return true;
103 pObjSh = 0;
104 return true;
107 return true;
110 //=========================================================================
112 SfxObjectItem::SfxObjectItem( sal_uInt16 nWhichId, SfxShell *pSh )
113 : SfxPoolItem( nWhichId ),
114 _pSh( pSh )
117 //--------------------------------------------------------------------
119 int SfxObjectItem::operator==( const SfxPoolItem &rItem ) const
121 SfxObjectItem *pOther = PTR_CAST(SfxObjectItem, &rItem);
122 return pOther->_pSh == _pSh;
125 //--------------------------------------------------------------------
127 SfxPoolItem* SfxObjectItem::Clone( SfxItemPool *) const
129 return new SfxObjectItem( Which(), _pSh );
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */