xref: /AOO41X/main/shell/source/win32/shlxthandler/ooofilt/propspec.cxx (revision f8e2c85a611dbc087707e0b32c9aee1ddf7485ca)
1*f8e2c85aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f8e2c85aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f8e2c85aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f8e2c85aSAndrew Rist  * distributed with this work for additional information
6*f8e2c85aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f8e2c85aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f8e2c85aSAndrew Rist  * "License"); you may not use this file except in compliance
9*f8e2c85aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f8e2c85aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f8e2c85aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f8e2c85aSAndrew Rist  * software distributed under the License is distributed on an
15*f8e2c85aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f8e2c85aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*f8e2c85aSAndrew Rist  * specific language governing permissions and limitations
18*f8e2c85aSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f8e2c85aSAndrew Rist  *************************************************************/
21*f8e2c85aSAndrew Rist 
22*f8e2c85aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_shell.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //+-------------------------------------------------------------------------
28cdf0e10cSrcweir //
29cdf0e10cSrcweir //  File:       propspec.cxx
30cdf0e10cSrcweir //
31cdf0e10cSrcweir //  Contents:   C++ wrappers for FULLPROPSPEC
32cdf0e10cSrcweir //
33cdf0e10cSrcweir //--------------------------------------------------------------------------
34cdf0e10cSrcweir #if defined _MSC_VER
35cdf0e10cSrcweir #pragma warning(push, 1)
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #include <windows.h>
38cdf0e10cSrcweir #ifdef _MSC_VER
39cdf0e10cSrcweir #pragma warning(disable: 4512)
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #include <filter.h>
42cdf0e10cSrcweir #if defined _MSC_VER
43cdf0e10cSrcweir #pragma warning(pop)
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include "propspec.hxx"
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //GUID CLSID_Storage = PSGUID_STORAGE;
49cdf0e10cSrcweir //
50cdf0e10cSrcweir //
51cdf0e10cSrcweir //refer to ms-help://MS.VSCC/MS.MSDNVS.2052/com/stgasstg_7agk.htm
52cdf0e10cSrcweir //FMTID_SummaryInformation
53cdf0e10cSrcweir //
54cdf0e10cSrcweir //GUID CLSID_SummaryInforation = {
55cdf0e10cSrcweir //    0xF29F85E0,
56cdf0e10cSrcweir //    0x4FF9,
57cdf0e10cSrcweir //    0x1068,
58cdf0e10cSrcweir //    { 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 }
59cdf0e10cSrcweir //};
60cdf0e10cSrcweir //+-------------------------------------------------------------------------
61cdf0e10cSrcweir //
62cdf0e10cSrcweir //  Member:     CFullPropSpec::CFullPropSpec, public
63cdf0e10cSrcweir //
64cdf0e10cSrcweir //  Synopsis:   Default constructor
65cdf0e10cSrcweir //
66cdf0e10cSrcweir //  Effects:    Defines property with null guid and propid 0
67cdf0e10cSrcweir //
68cdf0e10cSrcweir //--------------------------------------------------------------------------
69cdf0e10cSrcweir 
CFullPropSpec()70cdf0e10cSrcweir CFullPropSpec::CFullPropSpec()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     memset( &_guidPropSet, 0, sizeof( _guidPropSet ) );
73cdf0e10cSrcweir     _psProperty.ulKind = PRSPEC_PROPID;
74cdf0e10cSrcweir     _psProperty.propid = 0;
75cdf0e10cSrcweir }
76cdf0e10cSrcweir //+-------------------------------------------------------------------------
77cdf0e10cSrcweir //
78cdf0e10cSrcweir //  Member:     CFullPropSpec::CFullPropSpec, public
79cdf0e10cSrcweir //
80cdf0e10cSrcweir //  Synopsis:   Construct propid based propspec
81cdf0e10cSrcweir //
82cdf0e10cSrcweir //  Arguments:  [guidPropSet]  -- Property set
83cdf0e10cSrcweir //              [pidProperty] -- Property
84cdf0e10cSrcweir //
85cdf0e10cSrcweir //--------------------------------------------------------------------------
CFullPropSpec(GUID const & guidPropSet,PROPID pidProperty)86cdf0e10cSrcweir CFullPropSpec::CFullPropSpec( GUID const & guidPropSet, PROPID pidProperty ) :
87cdf0e10cSrcweir     _guidPropSet( guidPropSet )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     _psProperty.ulKind = PRSPEC_PROPID;
90cdf0e10cSrcweir     _psProperty.propid = pidProperty;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir //+-------------------------------------------------------------------------
93cdf0e10cSrcweir //
94cdf0e10cSrcweir //  Member:     CFullPropSpec::CFullPropSpec, public
95cdf0e10cSrcweir //
96cdf0e10cSrcweir //  Synopsis:   Construct name based propspec
97cdf0e10cSrcweir //
98cdf0e10cSrcweir //  Arguments:  [guidPropSet] -- Property set
99cdf0e10cSrcweir //              [wcsProperty] -- Property
100cdf0e10cSrcweir //
101cdf0e10cSrcweir //--------------------------------------------------------------------------
CFullPropSpec(GUID const & guidPropSet,WCHAR const * wcsProperty)102cdf0e10cSrcweir CFullPropSpec::CFullPropSpec( GUID const & guidPropSet,
103cdf0e10cSrcweir                               WCHAR const * wcsProperty ) :
104cdf0e10cSrcweir     _guidPropSet( guidPropSet )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir     _psProperty.ulKind = PRSPEC_PROPID;
107cdf0e10cSrcweir     SetProperty( wcsProperty );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir //+-------------------------------------------------------------------------
110cdf0e10cSrcweir //
111cdf0e10cSrcweir //  Member:     CFullPropSpec::CFullPropSpec, public
112cdf0e10cSrcweir //
113cdf0e10cSrcweir //  Synopsis:   Copy constructor
114cdf0e10cSrcweir //
115cdf0e10cSrcweir //  Arguments:  [src] -- Source property spec
116cdf0e10cSrcweir //
117cdf0e10cSrcweir //--------------------------------------------------------------------------
CFullPropSpec(CFullPropSpec const & src)118cdf0e10cSrcweir CFullPropSpec::CFullPropSpec( CFullPropSpec const & src ) :
119cdf0e10cSrcweir     _guidPropSet( src._guidPropSet )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     _psProperty.ulKind = src._psProperty.ulKind;
122cdf0e10cSrcweir     if ( _psProperty.ulKind == PRSPEC_LPWSTR )
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         if ( src._psProperty.lpwstr )
125cdf0e10cSrcweir         {
126cdf0e10cSrcweir             _psProperty.ulKind = PRSPEC_PROPID;
127cdf0e10cSrcweir             SetProperty( src._psProperty.lpwstr );
128cdf0e10cSrcweir         }
129cdf0e10cSrcweir         else
130cdf0e10cSrcweir             _psProperty.lpwstr = 0;
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir     else
133cdf0e10cSrcweir     {
134cdf0e10cSrcweir         _psProperty.propid = src._psProperty.propid;
135cdf0e10cSrcweir     }
136cdf0e10cSrcweir }
operator new(size_t,void * p)137cdf0e10cSrcweir inline void * operator new( size_t /*size*/, void * p )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     return( p );
140cdf0e10cSrcweir }
141cdf0e10cSrcweir //+-------------------------------------------------------------------------
142cdf0e10cSrcweir //
143cdf0e10cSrcweir //  Member:     CFullPropSpec::operator=, public
144cdf0e10cSrcweir //
145cdf0e10cSrcweir //  Synopsis:   Assignment operator
146cdf0e10cSrcweir //
147cdf0e10cSrcweir //  Arguments:  [Property] -- Source property
148cdf0e10cSrcweir //
149cdf0e10cSrcweir //--------------------------------------------------------------------------
operator =(CFullPropSpec const & Property)150cdf0e10cSrcweir CFullPropSpec & CFullPropSpec::operator=( CFullPropSpec const & Property )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     // Clean up.
153cdf0e10cSrcweir     this->CFullPropSpec::~CFullPropSpec();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir #ifdef _MSC_VER
156cdf0e10cSrcweir #pragma warning( disable : 4291 )           // unmatched operator new
157cdf0e10cSrcweir #endif
158cdf0e10cSrcweir     new (this) CFullPropSpec( Property );
159cdf0e10cSrcweir #ifdef _MSC_VER
160cdf0e10cSrcweir #pragma warning( default : 4291 )
161cdf0e10cSrcweir #endif
162cdf0e10cSrcweir     return *this;
163cdf0e10cSrcweir }
~CFullPropSpec()164cdf0e10cSrcweir CFullPropSpec::~CFullPropSpec()
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
167cdf0e10cSrcweir          _psProperty.lpwstr )
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         CoTaskMemFree( _psProperty.lpwstr );
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir }
SetProperty(PROPID pidProperty)172cdf0e10cSrcweir void CFullPropSpec::SetProperty( PROPID pidProperty )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir     if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
175cdf0e10cSrcweir          0 != _psProperty.lpwstr )
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         CoTaskMemFree( _psProperty.lpwstr );
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir     _psProperty.ulKind = PRSPEC_PROPID;
180cdf0e10cSrcweir     _psProperty.propid = pidProperty;
181cdf0e10cSrcweir }
SetProperty(WCHAR const * wcsProperty)182cdf0e10cSrcweir BOOL CFullPropSpec::SetProperty( WCHAR const * wcsProperty )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
185cdf0e10cSrcweir          0 != _psProperty.lpwstr )
186cdf0e10cSrcweir     {
187cdf0e10cSrcweir         CoTaskMemFree( _psProperty.lpwstr );
188cdf0e10cSrcweir     }
189cdf0e10cSrcweir     _psProperty.ulKind = PRSPEC_LPWSTR;
190cdf0e10cSrcweir     int len = (int) ( (wcslen( wcsProperty ) + 1) * sizeof( WCHAR ) );
191cdf0e10cSrcweir     _psProperty.lpwstr = (WCHAR *)CoTaskMemAlloc( len );
192cdf0e10cSrcweir     if ( 0 != _psProperty.lpwstr )
193cdf0e10cSrcweir     {
194cdf0e10cSrcweir         memcpy( _psProperty.lpwstr,
195cdf0e10cSrcweir                 wcsProperty,
196cdf0e10cSrcweir                 len );
197cdf0e10cSrcweir         return( TRUE );
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir     else
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         _psProperty.lpwstr = 0;
202cdf0e10cSrcweir         return( FALSE );
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir }
operator ==(CFullPropSpec const & prop) const205cdf0e10cSrcweir int CFullPropSpec::operator==( CFullPropSpec const & prop ) const
206cdf0e10cSrcweir {
207cdf0e10cSrcweir     if ( memcmp( &prop._guidPropSet,
208cdf0e10cSrcweir                  &_guidPropSet,
209cdf0e10cSrcweir                  sizeof( _guidPropSet ) ) != 0 ||
210cdf0e10cSrcweir          prop._psProperty.ulKind != _psProperty.ulKind )
211cdf0e10cSrcweir     {
212cdf0e10cSrcweir         return( 0 );
213cdf0e10cSrcweir     }
214cdf0e10cSrcweir     switch( _psProperty.ulKind )
215cdf0e10cSrcweir     {
216cdf0e10cSrcweir     case PRSPEC_LPWSTR:
217cdf0e10cSrcweir         return( _wcsicmp( GetPropertyName(), prop.GetPropertyName() ) == 0 );
218cdf0e10cSrcweir         break;
219cdf0e10cSrcweir     case PRSPEC_PROPID:
220cdf0e10cSrcweir         return( GetPropertyPropid() == prop.GetPropertyPropid() );
221cdf0e10cSrcweir         break;
222cdf0e10cSrcweir     default:
223cdf0e10cSrcweir         return( 0 );
224cdf0e10cSrcweir         break;
225cdf0e10cSrcweir     }
226cdf0e10cSrcweir }
operator !=(CFullPropSpec const & prop) const227cdf0e10cSrcweir int CFullPropSpec::operator!=( CFullPropSpec const & prop ) const
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     if (*this == prop)
230cdf0e10cSrcweir         return( 0 );
231cdf0e10cSrcweir     else
232cdf0e10cSrcweir         return( 1 );
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235