bump product version to 4.1.6.2
[LibreOffice.git] / shell / source / win32 / shlxthandler / classfactory.cxx
blob018333b154ed8f01b973a3d682e1e4771f1d6ac0
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 .
20 #undef OSL_DEBUG_LEVEL
23 #include <osl/diagnose.h>
25 #include "internal/global.hxx"
26 #include "classfactory.hxx"
27 #include "internal/infotips.hxx"
28 #include "internal/propsheets.hxx"
29 #include "internal/columninfo.hxx"
30 #ifdef __MINGW32__
31 #include <algorithm>
32 using ::std::max;
33 using ::std::min;
34 #endif
35 #include "internal/thumbviewer.hxx"
36 #include "internal/shlxthdl.hxx"
38 //-----------------------------
40 long CClassFactory::s_ServerLocks = 0;
42 //-----------------------------
44 CClassFactory::CClassFactory(const CLSID& clsid) :
45 m_RefCnt(1),
46 m_Clsid(clsid)
48 InterlockedIncrement(&g_DllRefCnt);
51 //-----------------------------
53 CClassFactory::~CClassFactory()
55 InterlockedDecrement(&g_DllRefCnt);
58 //-----------------------------
59 // IUnknown methods
60 //-----------------------------
62 HRESULT STDMETHODCALLTYPE CClassFactory::QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject)
64 *ppvObject = 0;
66 if (IID_IUnknown == riid || IID_IClassFactory == riid)
68 IUnknown* pUnk = this;
69 pUnk->AddRef();
70 *ppvObject = pUnk;
71 return S_OK;
74 return E_NOINTERFACE;
77 //-----------------------------
79 ULONG STDMETHODCALLTYPE CClassFactory::AddRef(void)
81 return InterlockedIncrement(&m_RefCnt);
84 //-----------------------------
86 ULONG STDMETHODCALLTYPE CClassFactory::Release(void)
88 long refcnt = InterlockedDecrement(&m_RefCnt);
90 if (0 == refcnt)
91 delete this;
93 return refcnt;
96 //-----------------------------
97 // IClassFactory methods
98 //-----------------------------
100 HRESULT STDMETHODCALLTYPE CClassFactory::CreateInstance(
101 IUnknown __RPC_FAR *pUnkOuter,
102 REFIID riid,
103 void __RPC_FAR *__RPC_FAR *ppvObject)
105 if ((pUnkOuter != NULL))
106 return CLASS_E_NOAGGREGATION;
108 IUnknown* pUnk = 0;
110 if (CLSID_PROPERTYSHEET_HANDLER == m_Clsid)
111 pUnk = static_cast<IShellExtInit*>(new CPropertySheet());
113 else if (CLSID_INFOTIP_HANDLER == m_Clsid)
114 pUnk = static_cast<IQueryInfo*>(new CInfoTip());
116 else if (CLSID_COLUMN_HANDLER == m_Clsid)
117 pUnk = static_cast<IColumnProvider*>(new CColumnInfo());
119 else if (CLSID_THUMBVIEWER_HANDLER == m_Clsid)
120 pUnk = static_cast<IExtractImage*>(new CThumbviewer());
122 OSL_POSTCOND(pUnk != 0, "Could not create COM object");
124 if (0 == pUnk)
125 return E_OUTOFMEMORY;
127 HRESULT hr = pUnk->QueryInterface(riid, ppvObject);
129 // if QueryInterface failed the component will destroy itself
130 pUnk->Release();
132 return hr;
135 //-----------------------------
137 HRESULT STDMETHODCALLTYPE CClassFactory::LockServer(BOOL fLock)
139 if (fLock)
140 InterlockedIncrement(&s_ServerLocks);
141 else
142 InterlockedDecrement(&s_ServerLocks);
144 return S_OK;
147 //-----------------------------
149 bool CClassFactory::IsLocked()
151 return (s_ServerLocks > 0);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */