Bump version to 5.0-14
[LibreOffice.git] / shell / source / win32 / shlxthandler / ooofilt / propspec.cxx
blob830bb4f486a0ae8ea9044ea714c4dda6734cdf92
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 //+-------------------------------------------------------------------------
22 // File: propspec.cxx
23 // Contents: C++ wrappers for FULLPROPSPEC
25 #if defined _MSC_VER
26 #pragma warning(push, 1)
27 #endif
28 #include <windows.h>
29 #include <filter.h>
30 #if defined _MSC_VER
31 #pragma warning(pop)
32 #endif
34 #include "propspec.hxx"
36 //refer to ms-help://MS.VSCC/MS.MSDNVS.2052/com/stgasstg_7agk.htm
37 //FMTID_SummaryInformation
38 //GUID CLSID_SummaryInforation = {
39 // 0xF29F85E0,
40 // 0x4FF9,
41 // 0x1068,
42 // { 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 }
43 //};
44 //+-------------------------------------------------------------------------
45 // Member: CFullPropSpec::CFullPropSpec, public
46 // Synopsis: Default constructor
47 // Effects: Defines property with null guid and propid 0
50 CFullPropSpec::CFullPropSpec()
52 memset( &_guidPropSet, 0, sizeof( _guidPropSet ) );
53 _psProperty.ulKind = PRSPEC_PROPID;
54 _psProperty.propid = 0;
56 //+-------------------------------------------------------------------------
57 // Member: CFullPropSpec::CFullPropSpec, public
58 // Synopsis: Construct propid based propspec
59 // Arguments: [guidPropSet] -- Property set
60 // [pidProperty] -- Property
62 CFullPropSpec::CFullPropSpec( GUID const & guidPropSet, PROPID pidProperty ) :
63 _guidPropSet( guidPropSet )
65 _psProperty.ulKind = PRSPEC_PROPID;
66 _psProperty.propid = pidProperty;
68 //+-------------------------------------------------------------------------
69 // Member: CFullPropSpec::CFullPropSpec, public
70 // Synopsis: Construct name based propspec
71 // Arguments: [guidPropSet] -- Property set
72 // [wcsProperty] -- Property
74 CFullPropSpec::CFullPropSpec( GUID const & guidPropSet,
75 WCHAR const * wcsProperty ) :
76 _guidPropSet( guidPropSet )
78 _psProperty.ulKind = PRSPEC_PROPID;
79 SetProperty( wcsProperty );
81 //+-------------------------------------------------------------------------
82 // Member: CFullPropSpec::CFullPropSpec, public
83 // Synopsis: Copy constructor
84 // Arguments: [src] -- Source property spec
86 CFullPropSpec::CFullPropSpec( CFullPropSpec const & src ) :
87 _guidPropSet( src._guidPropSet )
89 _psProperty.ulKind = src._psProperty.ulKind;
90 if ( _psProperty.ulKind == PRSPEC_LPWSTR )
92 if ( src._psProperty.lpwstr )
94 _psProperty.ulKind = PRSPEC_PROPID;
95 SetProperty( src._psProperty.lpwstr );
97 else
98 _psProperty.lpwstr = 0;
100 else
102 _psProperty.propid = src._psProperty.propid;
105 inline void * operator new( size_t /*size*/, void * p )
107 return p;
109 //+-------------------------------------------------------------------------
110 // Member: CFullPropSpec::operator=, public
111 // Synopsis: Assignment operator
112 // Arguments: [Property] -- Source property
114 CFullPropSpec & CFullPropSpec::operator=( CFullPropSpec const & Property )
116 // Clean up.
117 this->CFullPropSpec::~CFullPropSpec();
119 #ifdef _MSC_VER
120 #pragma warning( disable : 4291 ) // unmatched operator new
121 #endif
122 new (this) CFullPropSpec( Property );
123 #ifdef _MSC_VER
124 #pragma warning( default : 4291 )
125 #endif
126 return *this;
128 CFullPropSpec::~CFullPropSpec()
130 if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
131 _psProperty.lpwstr )
133 CoTaskMemFree( _psProperty.lpwstr );
136 void CFullPropSpec::SetProperty( PROPID pidProperty )
138 if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
139 0 != _psProperty.lpwstr )
141 CoTaskMemFree( _psProperty.lpwstr );
143 _psProperty.ulKind = PRSPEC_PROPID;
144 _psProperty.propid = pidProperty;
146 BOOL CFullPropSpec::SetProperty( WCHAR const * wcsProperty )
148 if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
149 0 != _psProperty.lpwstr )
151 CoTaskMemFree( _psProperty.lpwstr );
153 _psProperty.ulKind = PRSPEC_LPWSTR;
154 int len = (int) ( (wcslen( wcsProperty ) + 1) * sizeof( WCHAR ) );
155 _psProperty.lpwstr = (WCHAR *)CoTaskMemAlloc( len );
156 if ( 0 != _psProperty.lpwstr )
158 memcpy( _psProperty.lpwstr,
159 wcsProperty,
160 len );
161 return TRUE;
163 else
165 _psProperty.lpwstr = 0;
166 return FALSE;
169 int CFullPropSpec::operator==( CFullPropSpec const & prop ) const
171 if ( memcmp( &prop._guidPropSet,
172 &_guidPropSet,
173 sizeof( _guidPropSet ) ) != 0 ||
174 prop._psProperty.ulKind != _psProperty.ulKind )
176 return 0;
178 switch( _psProperty.ulKind )
180 case PRSPEC_LPWSTR:
181 return( _wcsicmp( GetPropertyName(), prop.GetPropertyName() ) == 0 );
182 break;
183 case PRSPEC_PROPID:
184 return( GetPropertyPropid() == prop.GetPropertyPropid() );
185 break;
186 default:
187 return 0;
188 break;
191 int CFullPropSpec::operator!=( CFullPropSpec const & prop ) const
193 if (*this == prop)
194 return 0;
195 else
196 return 1;
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */