update dev300-m58
[ooovba.git] / shell / source / win32 / shlxthandler / classfactory.cxx
bloba7b729d03a718c373591d66e7f19b72ec12997f5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: classfactory.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
33 #include "internal/global.hxx"
34 #include "classfactory.hxx"
35 #include "internal/infotips.hxx"
36 #include "internal/propsheets.hxx"
37 #include "internal/columninfo.hxx"
38 #ifdef __MINGW32__
39 #include <algorithm>
40 using ::std::max;
41 using ::std::min;
42 #endif
43 #include "internal/thumbviewer.hxx"
44 #include "internal/shlxthdl.hxx"
46 //-----------------------------
48 //-----------------------------
50 long CClassFactory::s_ServerLocks = 0;
52 //-----------------------------
54 //-----------------------------
56 CClassFactory::CClassFactory(const CLSID& clsid) :
57 m_RefCnt(1),
58 m_Clsid(clsid)
60 InterlockedIncrement(&g_DllRefCnt);
63 //-----------------------------
65 //-----------------------------
67 CClassFactory::~CClassFactory()
69 InterlockedDecrement(&g_DllRefCnt);
72 //-----------------------------
73 // IUnknown methods
74 //-----------------------------
76 HRESULT STDMETHODCALLTYPE CClassFactory::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
78 *ppvObject = 0;
80 if (IID_IUnknown == riid || IID_IClassFactory == riid)
82 IUnknown* pUnk = this;
83 pUnk->AddRef();
84 *ppvObject = pUnk;
85 return S_OK;
88 return E_NOINTERFACE;
91 //-----------------------------
93 //-----------------------------
95 ULONG STDMETHODCALLTYPE CClassFactory::AddRef(void)
97 return InterlockedIncrement(&m_RefCnt);
100 //-----------------------------
102 //-----------------------------
104 ULONG STDMETHODCALLTYPE CClassFactory::Release(void)
106 long refcnt = InterlockedDecrement(&m_RefCnt);
108 if (0 == refcnt)
109 delete this;
111 return refcnt;
114 //-----------------------------
115 // IClassFactory methods
116 //-----------------------------
118 HRESULT STDMETHODCALLTYPE CClassFactory::CreateInstance(
119 IUnknown __RPC_FAR *pUnkOuter,
120 REFIID riid,
121 void __RPC_FAR *__RPC_FAR *ppvObject)
123 if ((pUnkOuter != NULL))
124 return CLASS_E_NOAGGREGATION;
126 IUnknown* pUnk = 0;
128 if (CLSID_PROPERTYSHEET_HANDLER == m_Clsid)
129 pUnk = static_cast<IShellExtInit*>(new CPropertySheet());
131 else if (CLSID_INFOTIP_HANDLER == m_Clsid)
132 pUnk = static_cast<IQueryInfo*>(new CInfoTip());
134 else if (CLSID_COLUMN_HANDLER == m_Clsid)
135 pUnk = static_cast<IColumnProvider*>(new CColumnInfo());
137 else if (CLSID_THUMBVIEWER_HANDLER == m_Clsid)
138 pUnk = static_cast<IExtractImage*>(new CThumbviewer());
140 POST_CONDITION(pUnk != 0, "Could not create COM object");
142 if (0 == pUnk)
143 return E_OUTOFMEMORY;
145 HRESULT hr = pUnk->QueryInterface(riid, ppvObject);
147 // if QueryInterface failed the component will destroy itself
148 pUnk->Release();
150 return hr;
153 //-----------------------------
155 //-----------------------------
157 HRESULT STDMETHODCALLTYPE CClassFactory::LockServer(BOOL fLock)
159 if (fLock)
160 InterlockedIncrement(&s_ServerLocks);
161 else
162 InterlockedDecrement(&s_ServerLocks);
164 return S_OK;
167 //-----------------------------
169 //-----------------------------
171 bool CClassFactory::IsLocked()
173 return (s_ServerLocks > 0);