summaryrefslogtreecommitdiff
path: root/include/systools
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2013-04-20 07:23:12 +0200
committerDavid Tardon <dtardon@redhat.com>2013-04-24 05:17:49 +0000
commit25ea7f0b5e81b0242ec6e6a761f874db16383d22 (patch)
tree96128c7185500cbe2a8d6a93f5ac576435ffc47e /include/systools
parent9ccd994d445c797a48cb89ce2b7449adc68b1007 (diff)
move sal_inc headers to include/
Change-Id: I840c681b7c500640d3983e05e9895f3fa8bb1313 Reviewed-on: https://gerrit.libreoffice.org/3501 Reviewed-by: David Tardon <dtardon@redhat.com> Tested-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'include/systools')
-rw-r--r--include/systools/win32/comptr.hxx229
-rw-r--r--include/systools/win32/comtools.hxx187
-rw-r--r--include/systools/win32/qswin32.h43
-rw-r--r--include/systools/win32/uwinapi.h58
4 files changed, 517 insertions, 0 deletions
diff --git a/include/systools/win32/comptr.hxx b/include/systools/win32/comptr.hxx
new file mode 100644
index 000000000000..7ef5123f3ac5
--- /dev/null
+++ b/include/systools/win32/comptr.hxx
@@ -0,0 +1,229 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef COMPTR_HXX
+#define COMPTR_HXX
+
+#include <sal/types.h>
+#include <osl/diagnose.h>
+#include <shobjidl.h>
+
+template< class T_INTERFACE ,
+ REFIID P_IID = IID_NULL ,
+ REFCLSID P_CLSID = CLSID_NULL >
+class ComPtr
+{
+ public:
+
+ //---------------------------------------------------------------------
+ /** initialize com ptr with null.
+ */
+ ComPtr()
+ {
+ m_pInterface = NULL;
+ }
+
+ //---------------------------------------------------------------------
+ /** initialize com ptr with given interface.
+ */
+ ComPtr(T_INTERFACE* pInterface)
+ {
+ m_pInterface = pInterface;
+ if (m_pInterface)
+ m_pInterface->AddRef();
+ }
+
+ //---------------------------------------------------------------------
+ /** copy ctor.
+ */
+ ComPtr(const ComPtr< T_INTERFACE, P_IID, P_CLSID >& aCopy)
+ {
+ m_pInterface = aCopy.m_pInterface;
+ if (m_pInterface)
+ m_pInterface->AddRef();
+ }
+
+ //---------------------------------------------------------------------
+ /** initialize object by quering external object for the right interface.
+ */
+ ComPtr(IUnknown* pIUnknown)
+ {
+ if (pIUnknown)
+ pIUnknown->QueryInterface(P_IID, (void**)&m_pInterface);
+ }
+
+ //---------------------------------------------------------------------
+ /** deinitialize com object right.
+ */
+ ~ComPtr()
+ {
+ release();
+ }
+
+ public:
+
+ //---------------------------------------------------------------------
+ HRESULT create()
+ {
+ return CoCreateInstance(P_CLSID, NULL, CLSCTX_ALL, P_IID, (void**)&m_pInterface);
+ }
+
+ //---------------------------------------------------------------------
+ operator T_INTERFACE*() const
+ {
+ return m_pInterface;
+ }
+
+ //---------------------------------------------------------------------
+ T_INTERFACE& operator*() const
+ {
+ return *m_pInterface;
+ }
+
+ //---------------------------------------------------------------------
+ T_INTERFACE** operator&()
+ {
+ return &m_pInterface;
+ }
+
+ //---------------------------------------------------------------------
+ T_INTERFACE* operator->() const
+ {
+ return m_pInterface;
+ }
+
+ //---------------------------------------------------------------------
+ T_INTERFACE* operator=(T_INTERFACE* pInterface)
+ {
+ if ( equals(pInterface) )
+ return m_pInterface;
+
+ m_pInterface->Release();
+ m_pInterface = pInterface;
+ if (m_pInterface)
+ m_pInterface->AddRef();
+
+ return m_pInterface;
+ }
+
+ //---------------------------------------------------------------------
+ T_INTERFACE* operator=(IUnknown* pIUnknown)
+ {
+ if (pIUnknown)
+ pIUnknown->QueryInterface(P_IID, (void**)&m_pInterface);
+ return m_pInterface;
+ }
+
+ //---------------------------------------------------------------------
+ T_INTERFACE* operator=(const ComPtr< T_INTERFACE, P_IID, P_CLSID >& aCopy)
+ {
+ m_pInterface = aCopy.m_pInterface;
+ if (m_pInterface)
+ m_pInterface->AddRef();
+
+ return m_pInterface;
+ }
+
+ //---------------------------------------------------------------------
+ T_INTERFACE* get() const
+ {
+ return m_pInterface;
+ }
+
+ //---------------------------------------------------------------------
+ void attach(T_INTERFACE* pInterface)
+ {
+ if (pInterface)
+ {
+ m_pInterface->Release();
+ m_pInterface = pInterface;
+ }
+ }
+
+ //---------------------------------------------------------------------
+ T_INTERFACE* detach()
+ {
+ T_INTERFACE* pInterface = m_pInterface;
+ m_pInterface = NULL;
+ return pInterface;
+ }
+
+ //---------------------------------------------------------------------
+ void release()
+ {
+ if (m_pInterface)
+ {
+ m_pInterface->Release();
+ m_pInterface = NULL;
+ }
+ }
+
+#ifndef __MINGW32__
+ //---------------------------------------------------------------------
+ template< class T_QUERYINTERFACE >
+ HRESULT query(T_QUERYINTERFACE** pQuery)
+ {
+ return m_pInterface->QueryInterface(__uuidof(T_QUERYINTERFACE), (void**)pQuery);
+ }
+#endif
+
+ //---------------------------------------------------------------------
+ HRESULT query(REFIID rIID ,
+ void** pQuery)
+ {
+ return m_pInterface->QueryInterface(rIID, pQuery);
+ }
+
+ //---------------------------------------------------------------------
+ HRESULT unknown(IUnknown** pQuery)
+ {
+ return m_pInterface->QueryInterface(IID_IUnknown, (void**)pQuery);
+ }
+
+ //---------------------------------------------------------------------
+ ::sal_Bool equals(IUnknown* pCheck)
+ {
+ if (
+ ( ! m_pInterface ) &&
+ ( ! pCheck )
+ )
+ return sal_True;
+
+ IUnknown* pCurrent = NULL;
+ m_pInterface->QueryInterface(IID_IUnknown, (void**)&pCurrent);
+
+ ::sal_Bool bEquals = (pCheck == pCurrent);
+ pCurrent->Release();
+
+ return bEquals;
+ }
+
+ //---------------------------------------------------------------------
+ ::sal_Bool is()
+ {
+ return (m_pInterface != 0);
+ }
+
+ private:
+ T_INTERFACE* m_pInterface;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/systools/win32/comtools.hxx b/include/systools/win32/comtools.hxx
new file mode 100644
index 000000000000..1ef61ea3d967
--- /dev/null
+++ b/include/systools/win32/comtools.hxx
@@ -0,0 +1,187 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <string>
+#include <stdexcept>
+#if defined _MSC_VER
+#pragma warning(push,1)
+#endif
+#include <objbase.h>
+#if defined _MSC_VER
+#pragma warning(pop)
+#endif
+
+namespace sal
+{
+namespace systools
+{
+ typedef int HRESULT;
+
+ /* Simple exception class for propagating COM errors */
+ class ComError : public std::runtime_error
+ {
+ public:
+ ComError(const std::string& message, HRESULT hr) :
+ std::runtime_error(message),
+ hr_(hr)
+ {}
+
+ HRESULT GetHresult() const
+ {
+ return hr_;
+ }
+
+ private:
+ HRESULT hr_;
+ };
+
+ /* A simple COM smart pointer template */
+ template <typename T>
+ class COMReference
+ {
+ public:
+ COMReference() :
+ com_ptr_(NULL)
+ {
+ }
+
+ explicit COMReference(T* comptr) :
+ com_ptr_(comptr)
+ {
+ addRef();
+ }
+
+ /* Explicitly controllable whether AddRef will be called or not */
+ COMReference(T* comptr, bool bAddRef) :
+ com_ptr_(comptr)
+ {
+ if (bAddRef)
+ addRef();
+ }
+
+ COMReference(const COMReference<T>& other) :
+ com_ptr_(other.com_ptr_)
+ {
+ addRef();
+ }
+
+ COMReference<T>& operator=(const COMReference<T>& other)
+ {
+ if (other.com_ptr_)
+ other.com_ptr_->AddRef();
+ release();
+ com_ptr_ = other.com_ptr_;
+ return *this;
+ }
+
+ COMReference<T>& operator=(T* comptr)
+ {
+ release();
+ com_ptr_ = comptr;
+ addRef();
+ return *this;
+ }
+
+ ~COMReference()
+ {
+ release();
+ }
+
+ template<typename InterfaceType>
+ COMReference<InterfaceType> QueryInterface(REFIID iid)
+ {
+ COMReference<InterfaceType> ip;
+ HRESULT hr = E_FAIL;
+ if (com_ptr_)
+ hr = com_ptr_->QueryInterface(iid, reinterpret_cast<LPVOID*>(&ip));
+
+ if (FAILED(hr))
+ throw ComError("QueryInterface failed: Interface not supported!", hr);
+
+ return ip;
+ }
+
+ T* operator->() const
+ {
+ return com_ptr_;
+ }
+
+ T& operator*() const
+ {
+ return *com_ptr_;
+ }
+
+ /* Necessary for assigning com_ptr_ from functions like
+ CoCreateInstance which require a 'void**' */
+ T** operator&()
+ {
+ release();
+ com_ptr_ = NULL;
+ return &com_ptr_;
+ }
+
+ T* get() const
+ {
+ return com_ptr_;
+ }
+
+ COMReference<T>& clear()
+ {
+ release();
+ com_ptr_ = NULL;
+ return *this;
+ }
+
+ bool is() const
+ {
+ return (com_ptr_ != NULL);
+ }
+
+ private:
+ ULONG addRef()
+ {
+ ULONG cnt = 0;
+ if (com_ptr_)
+ cnt = com_ptr_->AddRef();
+ return cnt;
+ }
+
+ ULONG release()
+ {
+ ULONG cnt = 0;
+ if (com_ptr_)
+ cnt = com_ptr_->Release();
+ return cnt;
+ }
+
+ private:
+ T* com_ptr_;
+ };
+
+} // systools
+} // sal
+
+/* Typedefs for some popular COM interfaces */
+typedef sal::systools::COMReference<IDataObject> IDataObjectPtr;
+typedef sal::systools::COMReference<IStream> IStreamPtr;
+typedef sal::systools::COMReference<IEnumFORMATETC> IEnumFORMATETCPtr;
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/systools/win32/qswin32.h b/include/systools/win32/qswin32.h
new file mode 100644
index 000000000000..ed268d26affd
--- /dev/null
+++ b/include/systools/win32/qswin32.h
@@ -0,0 +1,43 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef _QSWIN32_H
+#define _QSWIN32_H
+
+#define QUICKSTART_CLASSNAMEA "LO Listener Class"
+#define QUICKSTART_WINDOWNAMEA "LO Listener Window"
+#define SHUTDOWN_QUICKSTART_MESSAGEA "LO KillTray"
+
+#define QUICKSTART_CLASSNAMEW L##QUICKSTART_CLASSNAMEA
+#define QUICKSTART_WINDOWNAMEW L##QUICKSTART_WINDOWNAMEA
+#define SHUTDOWN_QUICKSTART_MESSAGEW L##SHUTDOWN_QUICKSTART_MESSAGEA
+
+#ifdef UNICODE
+# define QUICKSTART_CLASSNAME QUICKSTART_CLASSNAMEW
+# define QUICKSTART_WINDOWNAME QUICKSTART_WINDOWNAMEW
+# define SHUTDOWN_QUICKSTART_MESSAGE SHUTDOWN_QUICKSTART_MESSAGEW
+#else
+# define QUICKSTART_CLASSNAME QUICKSTART_CLASSNAMEA
+# define QUICKSTART_WINDOWNAME QUICKSTART_WINDOWNAMEA
+# define SHUTDOWN_QUICKSTART_MESSAGE SHUTDOWN_QUICKSTART_MESSAGEA
+#endif
+
+#endif /* _QSWIN32_H */
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/systools/win32/uwinapi.h b/include/systools/win32/uwinapi.h
new file mode 100644
index 000000000000..5c4c88c415f1
--- /dev/null
+++ b/include/systools/win32/uwinapi.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+#include <sal/macros.h>
+#ifdef _UWINAPI_
+# define _KERNEL32_
+# define _USER32_
+# define _SHELL32_
+#endif
+
+#ifndef _WINDOWS_
+#ifdef _MSC_VER
+# pragma warning(push,1) /* disable warnings within system headers */
+#endif
+# include <windows.h>
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+#endif
+
+#ifdef __MINGW32__
+#include <basetyps.h>
+#ifdef _UWINAPI_
+#define WINBASEAPI
+#endif
+#endif
+
+#ifdef __cplusplus
+
+inline bool IsValidHandle(HANDLE handle)
+{
+ return handle != INVALID_HANDLE_VALUE && handle != NULL;
+}
+
+#else /* __cplusplus */
+
+#define IsValidHandle(Handle) ((DWORD)(Handle) + 1 > 1)
+
+#endif /* __cplusplus */
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */