[DMUSIC]
[reactos.git] / reactos / dll / directx / wine / dmusic / dmobject.c
1 /*
2 * Base IDirectMusicObject Implementation
3 *
4 * Copyright (C) 2003-2004 Rok Mandeljc
5 * Copyright (C) 2014 Michael Stefaniuc
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "dmusic_private.h"
23
24 /* Generic IDirectMusicObject methods */
25 static inline struct dmobject *impl_from_IDirectMusicObject(IDirectMusicObject *iface)
26 {
27 return CONTAINING_RECORD(iface, struct dmobject, IDirectMusicObject_iface);
28 }
29
30 HRESULT WINAPI dmobj_IDirectMusicObject_QueryInterface(IDirectMusicObject *iface, REFIID riid,
31 void **ret_iface)
32 {
33 struct dmobject *This = impl_from_IDirectMusicObject(iface);
34 return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface);
35 }
36
37 ULONG WINAPI dmobj_IDirectMusicObject_AddRef(IDirectMusicObject *iface)
38 {
39 struct dmobject *This = impl_from_IDirectMusicObject(iface);
40 return IUnknown_AddRef(This->outer_unk);
41 }
42
43 ULONG WINAPI dmobj_IDirectMusicObject_Release(IDirectMusicObject *iface)
44 {
45 struct dmobject *This = impl_from_IDirectMusicObject(iface);
46 return IUnknown_Release(This->outer_unk);
47 }
48
49 HRESULT WINAPI dmobj_IDirectMusicObject_GetDescriptor(IDirectMusicObject *iface,
50 DMUS_OBJECTDESC *desc)
51 {
52 struct dmobject *This = impl_from_IDirectMusicObject(iface);
53
54 TRACE("(%p/%p)->(%p)\n", iface, This, desc);
55
56 if (!desc)
57 return E_POINTER;
58
59 memcpy(desc, &This->desc, This->desc.dwSize);
60
61 return S_OK;
62 }
63
64 HRESULT WINAPI dmobj_IDirectMusicObject_SetDescriptor(IDirectMusicObject *iface,
65 DMUS_OBJECTDESC *desc)
66 {
67 struct dmobject *This = impl_from_IDirectMusicObject(iface);
68 HRESULT ret = S_OK;
69
70 TRACE("(%p, %p)\n", iface, desc);
71
72 if (!desc)
73 return E_POINTER;
74
75 /* Immutable property */
76 if (desc->dwValidData & DMUS_OBJ_CLASS)
77 {
78 desc->dwValidData &= ~DMUS_OBJ_CLASS;
79 ret = S_FALSE;
80 }
81 /* Set only valid fields */
82 if (desc->dwValidData & DMUS_OBJ_OBJECT)
83 This->desc.guidObject = desc->guidObject;
84 if (desc->dwValidData & DMUS_OBJ_NAME)
85 lstrcpynW(This->desc.wszName, desc->wszName, DMUS_MAX_NAME);
86 if (desc->dwValidData & DMUS_OBJ_CATEGORY)
87 lstrcpynW(This->desc.wszCategory, desc->wszCategory, DMUS_MAX_CATEGORY);
88 if (desc->dwValidData & DMUS_OBJ_FILENAME)
89 lstrcpynW(This->desc.wszFileName, desc->wszFileName, DMUS_MAX_FILENAME);
90 if (desc->dwValidData & DMUS_OBJ_VERSION)
91 This->desc.vVersion = desc->vVersion;
92 if (desc->dwValidData & DMUS_OBJ_DATE)
93 This->desc.ftDate = desc->ftDate;
94 if (desc->dwValidData & DMUS_OBJ_MEMORY) {
95 This->desc.llMemLength = desc->llMemLength;
96 memcpy(This->desc.pbMemData, desc->pbMemData, desc->llMemLength);
97 }
98 if (desc->dwValidData & DMUS_OBJ_STREAM)
99 IStream_Clone(desc->pStream, &This->desc.pStream);
100
101 This->desc.dwValidData |= desc->dwValidData;
102
103 return ret;
104 }
105
106 /* Generic IPersistStream methods */
107 static inline struct dmobject *impl_from_IPersistStream(IPersistStream *iface)
108 {
109 return CONTAINING_RECORD(iface, struct dmobject, IPersistStream_iface);
110 }
111
112 HRESULT WINAPI dmobj_IPersistStream_QueryInterface(IPersistStream *iface, REFIID riid,
113 void **ret_iface)
114 {
115 struct dmobject *This = impl_from_IPersistStream(iface);
116 return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface);
117 }
118
119 ULONG WINAPI dmobj_IPersistStream_AddRef(IPersistStream *iface)
120 {
121 struct dmobject *This = impl_from_IPersistStream(iface);
122 return IUnknown_AddRef(This->outer_unk);
123 }
124
125 ULONG WINAPI dmobj_IPersistStream_Release(IPersistStream *iface)
126 {
127 struct dmobject *This = impl_from_IPersistStream(iface);
128 return IUnknown_Release(This->outer_unk);
129 }
130
131 /* IPersistStream methods not implemented in native */
132 HRESULT WINAPI unimpl_IPersistStream_GetClassID(IPersistStream *iface, CLSID *class)
133 {
134 TRACE("(%p, %p): method not implemented\n", iface, class);
135 return E_NOTIMPL;
136 }
137
138 HRESULT WINAPI unimpl_IPersistStream_IsDirty(IPersistStream *iface)
139 {
140 TRACE("(%p): method not implemented, always returning S_FALSE\n", iface);
141 return S_FALSE;
142 }
143
144 HRESULT WINAPI unimpl_IPersistStream_Save(IPersistStream *iface, IStream *stream,
145 BOOL clear_dirty)
146 {
147 TRACE("(%p, %p, %d): method not implemented\n", iface, stream, clear_dirty);
148 return E_NOTIMPL;
149 }
150
151 HRESULT WINAPI unimpl_IPersistStream_GetSizeMax(IPersistStream *iface, ULARGE_INTEGER *size)
152 {
153 TRACE("(%p, %p): method not implemented\n", iface, size);
154 return E_NOTIMPL;
155 }
156
157
158 void dmobject_init(struct dmobject *dmobj, const GUID *class, IUnknown *outer_unk)
159 {
160 dmobj->outer_unk = outer_unk;
161 dmobj->desc.dwSize = sizeof(dmobj->desc);
162 dmobj->desc.dwValidData = DMUS_OBJ_CLASS;
163 dmobj->desc.guidClass = *class;
164 }