| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 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/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 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 . |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
//+------------------------------------------------------------------------- |
| 22 |
// File: propspec.cxx |
| 23 |
// Contents: C++ wrappers for FULLPROPSPEC |
| 24 |
|
| 25 |
#include <sal/config.h> |
| 26 |
|
| 27 |
#include <new> |
| 28 |
|
| 29 |
#if !defined WIN32_LEAN_AND_MEAN |
| 30 |
# define WIN32_LEAN_AND_MEAN |
| 31 |
#endif |
| 32 |
#include <windows.h> |
| 33 |
#include <filter.h> |
| 34 |
|
| 35 |
#include "propspec.hxx" |
| 36 |
|
| 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 |
| 49 |
|
| 50 |
|
| 51 |
CFullPropSpec::CFullPropSpec() |
| 52 |
{ |
| 53 |
_psProperty.ulKind = PRSPEC_PROPID; |
| 54 |
_psProperty.propid = 0; |
| 55 |
} |
| 56 |
//+------------------------------------------------------------------------- |
| 57 |
// Member: CFullPropSpec::CFullPropSpec, public |
| 58 |
// Synopsis: Construct propid based propspec |
| 59 |
// Arguments: [guidPropSet] -- Property set |
| 60 |
// [pidProperty] -- Property |
| 61 |
|
| 62 |
CFullPropSpec::CFullPropSpec( GUID const & guidPropSet, PROPID pidProperty ) : |
| 63 |
_guidPropSet( guidPropSet ) |
| 64 |
{ |
| 65 |
_psProperty.ulKind = PRSPEC_PROPID; |
| 66 |
_psProperty.propid = pidProperty; |
| 67 |
} |
| 68 |
//+------------------------------------------------------------------------- |
| 69 |
// Member: CFullPropSpec::CFullPropSpec, public |
| 70 |
// Synopsis: Construct name based propspec |
| 71 |
// Arguments: [guidPropSet] -- Property set |
| 72 |
// [wcsProperty] -- Property |
| 73 |
|
| 74 |
CFullPropSpec::CFullPropSpec( GUID const & guidPropSet, |
| 75 |
WCHAR const * wcsProperty ) : |
| 76 |
_guidPropSet( guidPropSet ) |
| 77 |
{ |
| 78 |
_psProperty.ulKind = PRSPEC_PROPID; |
| 79 |
SetProperty( wcsProperty ); |
| 80 |
} |
| 81 |
//+------------------------------------------------------------------------- |
| 82 |
// Member: CFullPropSpec::CFullPropSpec, public |
| 83 |
// Synopsis: Copy constructor |
| 84 |
// Arguments: [src] -- Source property spec |
| 85 |
|
| 86 |
CFullPropSpec::CFullPropSpec( CFullPropSpec const & src ) : |
| 87 |
_guidPropSet( src._guidPropSet ) |
| 88 |
{ |
| 89 |
_psProperty.ulKind = src._psProperty.ulKind; |
| 90 |
if ( _psProperty.ulKind == PRSPEC_LPWSTR ) |
| 91 |
{ |
| 92 |
if ( src._psProperty.lpwstr ) |
| 93 |
{ |
| 94 |
_psProperty.ulKind = PRSPEC_PROPID; |
| 95 |
SetProperty( src._psProperty.lpwstr ); |
| 96 |
} |
| 97 |
else |
| 98 |
_psProperty.lpwstr = nullptr; |
| 99 |
} |
| 100 |
else |
| 101 |
{ |
| 102 |
_psProperty.propid = src._psProperty.propid; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
//+------------------------------------------------------------------------- |
| 107 |
// Member: CFullPropSpec::operator=, public |
| 108 |
// Synopsis: Assignment operator |
| 109 |
// Arguments: [Property] -- Source property |
| 110 |
|
| 111 |
CFullPropSpec & CFullPropSpec::operator=( CFullPropSpec const & Property ) |
| 112 |
{ |
| 113 |
if (this != &Property) |
| 114 |
{ |
| 115 |
// Clean up. |
| 116 |
this->CFullPropSpec::~CFullPropSpec(); |
| 117 |
|
| 118 |
::new (this) CFullPropSpec( Property ); |
| 119 |
} |
| 120 |
return *this; |
| 121 |
} |
| 122 |
|
| 123 |
CFullPropSpec::~CFullPropSpec() |
| 124 |
{ |
| 125 |
if ( _psProperty.ulKind == PRSPEC_LPWSTR && |
| 126 |
_psProperty.lpwstr ) |
| 127 |
{ |
| 128 |
CoTaskMemFree( _psProperty.lpwstr ); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
void CFullPropSpec::SetProperty( PROPID pidProperty ) |
| 133 |
{ |
| 134 |
if ( _psProperty.ulKind == PRSPEC_LPWSTR && |
| 135 |
nullptr != _psProperty.lpwstr ) |
| 136 |
{ |
| 137 |
CoTaskMemFree( _psProperty.lpwstr ); |
| 138 |
} |
| 139 |
_psProperty.ulKind = PRSPEC_PROPID; |
| 140 |
_psProperty.propid = pidProperty; |
| 141 |
} |
| 142 |
BOOL CFullPropSpec::SetProperty( WCHAR const * wcsProperty ) |
| 143 |
{ |
| 144 |
if ( _psProperty.ulKind == PRSPEC_LPWSTR && |
| 145 |
nullptr != _psProperty.lpwstr ) |
| 146 |
{ |
| 147 |
CoTaskMemFree( _psProperty.lpwstr ); |
| 148 |
} |
| 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 ) |
| 153 |
{ |
| 154 |
memcpy( _psProperty.lpwstr, |
| 155 |
wcsProperty, |
| 156 |
len ); |
| 157 |
return TRUE; |
| 158 |
} |
| 159 |
else |
| 160 |
{ |
| 161 |
_psProperty.lpwstr = nullptr; |
| 162 |
return FALSE; |
| 163 |
} |
| 164 |
} |
| 165 |
bool CFullPropSpec::operator==( CFullPropSpec const & prop ) const |
| 166 |
{ |
| 167 |
if ( memcmp( &prop._guidPropSet, |
| 168 |
&_guidPropSet, |
| 169 |
sizeof( _guidPropSet ) ) != 0 || |
| 170 |
prop._psProperty.ulKind != _psProperty.ulKind ) |
| 171 |
{ |
| 172 |
return false; |
| 173 |
} |
| 174 |
switch( _psProperty.ulKind ) |
| 175 |
{ |
| 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; |
| 182 |
} |
| 183 |
} |
| 184 |
bool CFullPropSpec::operator!=( CFullPropSpec const & prop ) const |
| 185 |
{ |
| 186 |
if (*this == prop) |
| 187 |
return false; |
| 188 |
else |
| 189 |
return true; |
| 190 |
} |
| 191 |
|
| 192 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |