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_shell.hxx"
26 
27 //+-------------------------------------------------------------------------
28 //
29 //  File:       propspec.cxx
30 //
31 //  Contents:   C++ wrappers for FULLPROPSPEC
32 //
33 //--------------------------------------------------------------------------
34 #if defined _MSC_VER
35 #pragma warning(push, 1)
36 #endif
37 #include <windows.h>
38 #ifdef _MSC_VER
39 #pragma warning(disable: 4512)
40 #endif
41 #include <filter.h>
42 #if defined _MSC_VER
43 #pragma warning(pop)
44 #endif
45 
46 #include "propspec.hxx"
47 
48 //GUID CLSID_Storage = PSGUID_STORAGE;
49 //
50 //
51 //refer to ms-help://MS.VSCC/MS.MSDNVS.2052/com/stgasstg_7agk.htm
52 //FMTID_SummaryInformation
53 //
54 //GUID CLSID_SummaryInforation = {
55 //    0xF29F85E0,
56 //    0x4FF9,
57 //    0x1068,
58 //    { 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 }
59 //};
60 //+-------------------------------------------------------------------------
61 //
62 //  Member:     CFullPropSpec::CFullPropSpec, public
63 //
64 //  Synopsis:   Default constructor
65 //
66 //  Effects:    Defines property with null guid and propid 0
67 //
68 //--------------------------------------------------------------------------
69 
CFullPropSpec()70 CFullPropSpec::CFullPropSpec()
71 {
72     memset( &_guidPropSet, 0, sizeof( _guidPropSet ) );
73     _psProperty.ulKind = PRSPEC_PROPID;
74     _psProperty.propid = 0;
75 }
76 //+-------------------------------------------------------------------------
77 //
78 //  Member:     CFullPropSpec::CFullPropSpec, public
79 //
80 //  Synopsis:   Construct propid based propspec
81 //
82 //  Arguments:  [guidPropSet]  -- Property set
83 //              [pidProperty] -- Property
84 //
85 //--------------------------------------------------------------------------
CFullPropSpec(GUID const & guidPropSet,PROPID pidProperty)86 CFullPropSpec::CFullPropSpec( GUID const & guidPropSet, PROPID pidProperty ) :
87     _guidPropSet( guidPropSet )
88 {
89     _psProperty.ulKind = PRSPEC_PROPID;
90     _psProperty.propid = pidProperty;
91 }
92 //+-------------------------------------------------------------------------
93 //
94 //  Member:     CFullPropSpec::CFullPropSpec, public
95 //
96 //  Synopsis:   Construct name based propspec
97 //
98 //  Arguments:  [guidPropSet] -- Property set
99 //              [wcsProperty] -- Property
100 //
101 //--------------------------------------------------------------------------
CFullPropSpec(GUID const & guidPropSet,WCHAR const * wcsProperty)102 CFullPropSpec::CFullPropSpec( GUID const & guidPropSet,
103                               WCHAR const * wcsProperty ) :
104     _guidPropSet( guidPropSet )
105 {
106     _psProperty.ulKind = PRSPEC_PROPID;
107     SetProperty( wcsProperty );
108 }
109 //+-------------------------------------------------------------------------
110 //
111 //  Member:     CFullPropSpec::CFullPropSpec, public
112 //
113 //  Synopsis:   Copy constructor
114 //
115 //  Arguments:  [src] -- Source property spec
116 //
117 //--------------------------------------------------------------------------
CFullPropSpec(CFullPropSpec const & src)118 CFullPropSpec::CFullPropSpec( CFullPropSpec const & src ) :
119     _guidPropSet( src._guidPropSet )
120 {
121     _psProperty.ulKind = src._psProperty.ulKind;
122     if ( _psProperty.ulKind == PRSPEC_LPWSTR )
123     {
124         if ( src._psProperty.lpwstr )
125         {
126             _psProperty.ulKind = PRSPEC_PROPID;
127             SetProperty( src._psProperty.lpwstr );
128         }
129         else
130             _psProperty.lpwstr = 0;
131     }
132     else
133     {
134         _psProperty.propid = src._psProperty.propid;
135     }
136 }
operator new(size_t,void * p)137 inline void * operator new( size_t /*size*/, void * p )
138 {
139     return( p );
140 }
141 //+-------------------------------------------------------------------------
142 //
143 //  Member:     CFullPropSpec::operator=, public
144 //
145 //  Synopsis:   Assignment operator
146 //
147 //  Arguments:  [Property] -- Source property
148 //
149 //--------------------------------------------------------------------------
operator =(CFullPropSpec const & Property)150 CFullPropSpec & CFullPropSpec::operator=( CFullPropSpec const & Property )
151 {
152     // Clean up.
153     this->CFullPropSpec::~CFullPropSpec();
154 
155 #ifdef _MSC_VER
156 #pragma warning( disable : 4291 )           // unmatched operator new
157 #endif
158     new (this) CFullPropSpec( Property );
159 #ifdef _MSC_VER
160 #pragma warning( default : 4291 )
161 #endif
162     return *this;
163 }
~CFullPropSpec()164 CFullPropSpec::~CFullPropSpec()
165 {
166     if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
167          _psProperty.lpwstr )
168     {
169         CoTaskMemFree( _psProperty.lpwstr );
170     }
171 }
SetProperty(PROPID pidProperty)172 void CFullPropSpec::SetProperty( PROPID pidProperty )
173 {
174     if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
175          0 != _psProperty.lpwstr )
176     {
177         CoTaskMemFree( _psProperty.lpwstr );
178     }
179     _psProperty.ulKind = PRSPEC_PROPID;
180     _psProperty.propid = pidProperty;
181 }
SetProperty(WCHAR const * wcsProperty)182 BOOL CFullPropSpec::SetProperty( WCHAR const * wcsProperty )
183 {
184     if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
185          0 != _psProperty.lpwstr )
186     {
187         CoTaskMemFree( _psProperty.lpwstr );
188     }
189     _psProperty.ulKind = PRSPEC_LPWSTR;
190     int len = (int) ( (wcslen( wcsProperty ) + 1) * sizeof( WCHAR ) );
191     _psProperty.lpwstr = (WCHAR *)CoTaskMemAlloc( len );
192     if ( 0 != _psProperty.lpwstr )
193     {
194         memcpy( _psProperty.lpwstr,
195                 wcsProperty,
196                 len );
197         return( TRUE );
198     }
199     else
200     {
201         _psProperty.lpwstr = 0;
202         return( FALSE );
203     }
204 }
operator ==(CFullPropSpec const & prop) const205 int CFullPropSpec::operator==( CFullPropSpec const & prop ) const
206 {
207     if ( memcmp( &prop._guidPropSet,
208                  &_guidPropSet,
209                  sizeof( _guidPropSet ) ) != 0 ||
210          prop._psProperty.ulKind != _psProperty.ulKind )
211     {
212         return( 0 );
213     }
214     switch( _psProperty.ulKind )
215     {
216     case PRSPEC_LPWSTR:
217         return( _wcsicmp( GetPropertyName(), prop.GetPropertyName() ) == 0 );
218         break;
219     case PRSPEC_PROPID:
220         return( GetPropertyPropid() == prop.GetPropertyPropid() );
221         break;
222     default:
223         return( 0 );
224         break;
225     }
226 }
operator !=(CFullPropSpec const & prop) const227 int CFullPropSpec::operator!=( CFullPropSpec const & prop ) const
228 {
229     if (*this == prop)
230         return( 0 );
231     else
232         return( 1 );
233 }
234 
235