1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_shell.hxx"
30 
31 //+-------------------------------------------------------------------------
32 //
33 //  File:       propspec.cxx
34 //
35 //  Contents:   C++ wrappers for FULLPROPSPEC
36 //
37 //--------------------------------------------------------------------------
38 #if defined _MSC_VER
39 #pragma warning(push, 1)
40 #endif
41 #include <windows.h>
42 #ifdef _MSC_VER
43 #pragma warning(disable: 4512)
44 #endif
45 #include <filter.h>
46 #if defined _MSC_VER
47 #pragma warning(pop)
48 #endif
49 
50 #include "propspec.hxx"
51 
52 //GUID CLSID_Storage = PSGUID_STORAGE;
53 //
54 //
55 //refer to ms-help://MS.VSCC/MS.MSDNVS.2052/com/stgasstg_7agk.htm
56 //FMTID_SummaryInformation
57 //
58 //GUID CLSID_SummaryInforation = {
59 //    0xF29F85E0,
60 //    0x4FF9,
61 //    0x1068,
62 //    { 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 }
63 //};
64 //+-------------------------------------------------------------------------
65 //
66 //  Member:     CFullPropSpec::CFullPropSpec, public
67 //
68 //  Synopsis:   Default constructor
69 //
70 //  Effects:    Defines property with null guid and propid 0
71 //
72 //--------------------------------------------------------------------------
73 
74 CFullPropSpec::CFullPropSpec()
75 {
76     memset( &_guidPropSet, 0, sizeof( _guidPropSet ) );
77     _psProperty.ulKind = PRSPEC_PROPID;
78     _psProperty.propid = 0;
79 }
80 //+-------------------------------------------------------------------------
81 //
82 //  Member:     CFullPropSpec::CFullPropSpec, public
83 //
84 //  Synopsis:   Construct propid based propspec
85 //
86 //  Arguments:  [guidPropSet]  -- Property set
87 //              [pidProperty] -- Property
88 //
89 //--------------------------------------------------------------------------
90 CFullPropSpec::CFullPropSpec( GUID const & guidPropSet, PROPID pidProperty ) :
91     _guidPropSet( guidPropSet )
92 {
93     _psProperty.ulKind = PRSPEC_PROPID;
94     _psProperty.propid = pidProperty;
95 }
96 //+-------------------------------------------------------------------------
97 //
98 //  Member:     CFullPropSpec::CFullPropSpec, public
99 //
100 //  Synopsis:   Construct name based propspec
101 //
102 //  Arguments:  [guidPropSet] -- Property set
103 //              [wcsProperty] -- Property
104 //
105 //--------------------------------------------------------------------------
106 CFullPropSpec::CFullPropSpec( GUID const & guidPropSet,
107                               WCHAR const * wcsProperty ) :
108     _guidPropSet( guidPropSet )
109 {
110     _psProperty.ulKind = PRSPEC_PROPID;
111     SetProperty( wcsProperty );
112 }
113 //+-------------------------------------------------------------------------
114 //
115 //  Member:     CFullPropSpec::CFullPropSpec, public
116 //
117 //  Synopsis:   Copy constructor
118 //
119 //  Arguments:  [src] -- Source property spec
120 //
121 //--------------------------------------------------------------------------
122 CFullPropSpec::CFullPropSpec( CFullPropSpec const & src ) :
123     _guidPropSet( src._guidPropSet )
124 {
125     _psProperty.ulKind = src._psProperty.ulKind;
126     if ( _psProperty.ulKind == PRSPEC_LPWSTR )
127     {
128         if ( src._psProperty.lpwstr )
129         {
130             _psProperty.ulKind = PRSPEC_PROPID;
131             SetProperty( src._psProperty.lpwstr );
132         }
133         else
134             _psProperty.lpwstr = 0;
135     }
136     else
137     {
138         _psProperty.propid = src._psProperty.propid;
139     }
140 }
141 inline void * operator new( size_t /*size*/, void * p )
142 {
143     return( p );
144 }
145 //+-------------------------------------------------------------------------
146 //
147 //  Member:     CFullPropSpec::operator=, public
148 //
149 //  Synopsis:   Assignment operator
150 //
151 //  Arguments:  [Property] -- Source property
152 //
153 //--------------------------------------------------------------------------
154 CFullPropSpec & CFullPropSpec::operator=( CFullPropSpec const & Property )
155 {
156     // Clean up.
157     this->CFullPropSpec::~CFullPropSpec();
158 
159 #ifdef _MSC_VER
160 #pragma warning( disable : 4291 )           // unmatched operator new
161 #endif
162     new (this) CFullPropSpec( Property );
163 #ifdef _MSC_VER
164 #pragma warning( default : 4291 )
165 #endif
166     return *this;
167 }
168 CFullPropSpec::~CFullPropSpec()
169 {
170     if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
171          _psProperty.lpwstr )
172     {
173         CoTaskMemFree( _psProperty.lpwstr );
174     }
175 }
176 void CFullPropSpec::SetProperty( PROPID pidProperty )
177 {
178     if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
179          0 != _psProperty.lpwstr )
180     {
181         CoTaskMemFree( _psProperty.lpwstr );
182     }
183     _psProperty.ulKind = PRSPEC_PROPID;
184     _psProperty.propid = pidProperty;
185 }
186 BOOL CFullPropSpec::SetProperty( WCHAR const * wcsProperty )
187 {
188     if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
189          0 != _psProperty.lpwstr )
190     {
191         CoTaskMemFree( _psProperty.lpwstr );
192     }
193     _psProperty.ulKind = PRSPEC_LPWSTR;
194     int len = (int) ( (wcslen( wcsProperty ) + 1) * sizeof( WCHAR ) );
195     _psProperty.lpwstr = (WCHAR *)CoTaskMemAlloc( len );
196     if ( 0 != _psProperty.lpwstr )
197     {
198         memcpy( _psProperty.lpwstr,
199                 wcsProperty,
200                 len );
201         return( TRUE );
202     }
203     else
204     {
205         _psProperty.lpwstr = 0;
206         return( FALSE );
207     }
208 }
209 int CFullPropSpec::operator==( CFullPropSpec const & prop ) const
210 {
211     if ( memcmp( &prop._guidPropSet,
212                  &_guidPropSet,
213                  sizeof( _guidPropSet ) ) != 0 ||
214          prop._psProperty.ulKind != _psProperty.ulKind )
215     {
216         return( 0 );
217     }
218     switch( _psProperty.ulKind )
219     {
220     case PRSPEC_LPWSTR:
221         return( _wcsicmp( GetPropertyName(), prop.GetPropertyName() ) == 0 );
222         break;
223     case PRSPEC_PROPID:
224         return( GetPropertyPropid() == prop.GetPropertyPropid() );
225         break;
226     default:
227         return( 0 );
228         break;
229     }
230 }
231 int CFullPropSpec::operator!=( CFullPropSpec const & prop ) const
232 {
233     if (*this == prop)
234         return( 0 );
235     else
236         return( 1 );
237 }
238 
239