Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / shell / source / win32 / shlxthandler / ooofilt / propspec.cxx
blobf03cef033b2b7d12d5329cf459f4b1032ca0c63b
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 #include <sal/config.h>
27 #include <new>
29 #if !defined WIN32_LEAN_AND_MEAN
30 # define WIN32_LEAN_AND_MEAN
31 #endif
32 #include <windows.h>
33 #include <filter.h>
35 #include "propspec.hxx"
37 //refer to ms-help://MS.VSCC/MS.MSDNVS.2052/com/stgasstg_7agk.htm
38 //FMTID_SummaryInformation
39 //GUID CLSID_SummaryInformation = {
40 // 0xF29F85E0,
41 // 0x4FF9,
42 // 0x1068,
43 // { 0xAB, 0x91, 0x08, 0x00, 0x2B, 0x27, 0xB3, 0xD9 }
44 //};
45 //+-------------------------------------------------------------------------
46 // Member: CFullPropSpec::CFullPropSpec, public
47 // Synopsis: Default constructor
48 // Effects: Defines property with null guid and propid 0
51 CFullPropSpec::CFullPropSpec()
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 = nullptr;
100 else
102 _psProperty.propid = src._psProperty.propid;
106 //+-------------------------------------------------------------------------
107 // Member: CFullPropSpec::operator=, public
108 // Synopsis: Assignment operator
109 // Arguments: [Property] -- Source property
111 CFullPropSpec & CFullPropSpec::operator=( CFullPropSpec const & Property )
113 if (this != &Property)
115 // Clean up.
116 this->CFullPropSpec::~CFullPropSpec();
118 ::new (this) CFullPropSpec( Property );
120 return *this;
123 CFullPropSpec::~CFullPropSpec()
125 if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
126 _psProperty.lpwstr )
128 CoTaskMemFree( _psProperty.lpwstr );
132 void CFullPropSpec::SetProperty( PROPID pidProperty )
134 if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
135 nullptr != _psProperty.lpwstr )
137 CoTaskMemFree( _psProperty.lpwstr );
139 _psProperty.ulKind = PRSPEC_PROPID;
140 _psProperty.propid = pidProperty;
142 BOOL CFullPropSpec::SetProperty( WCHAR const * wcsProperty )
144 if ( _psProperty.ulKind == PRSPEC_LPWSTR &&
145 nullptr != _psProperty.lpwstr )
147 CoTaskMemFree( _psProperty.lpwstr );
149 _psProperty.ulKind = PRSPEC_LPWSTR;
150 int len = static_cast<int>( (wcslen( wcsProperty ) + 1) * sizeof( WCHAR ) );
151 _psProperty.lpwstr = static_cast<WCHAR *>(CoTaskMemAlloc( len ));
152 if ( nullptr != _psProperty.lpwstr )
154 memcpy( _psProperty.lpwstr,
155 wcsProperty,
156 len );
157 return TRUE;
159 else
161 _psProperty.lpwstr = nullptr;
162 return FALSE;
165 bool CFullPropSpec::operator==( CFullPropSpec const & prop ) const
167 if ( memcmp( &prop._guidPropSet,
168 &_guidPropSet,
169 sizeof( _guidPropSet ) ) != 0 ||
170 prop._psProperty.ulKind != _psProperty.ulKind )
172 return false;
174 switch( _psProperty.ulKind )
176 case PRSPEC_LPWSTR:
177 return( _wcsicmp( GetPropertyName(), prop.GetPropertyName() ) == 0 );
178 case PRSPEC_PROPID:
179 return( GetPropertyPropid() == prop.GetPropertyPropid() );
180 default:
181 return false;
184 bool CFullPropSpec::operator!=( CFullPropSpec const & prop ) const
186 if (*this == prop)
187 return false;
188 else
189 return true;
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */