]> git.lyx.org Git - lyx.git/blobdiff - src/support/os_win32.h
Add acmart template
[lyx.git] / src / support / os_win32.h
index 7ee35d09eabd449493baf6390fff5583ff9eeab2..42016f7094eb7f33abe56afd7fb77b4fdcd8d5ee 100644 (file)
-// os_win32.h copyright "Ruurd A. Reitsma" <R.A.Reitsma@wbmt.tudelft.nl>
-
-#ifndef _OS_WIN32_H_
-#define _OS_WIN32_H_
-
-//Avoid zillions of windows includes
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-
-#include <windows.h>
-
-// Avoid some very annoying macros from MFC 
-#  undef max
-#  undef min
-
-#if defined( __SGI_STL_PORT )
-
-  namespace std {
-    // These overloads prevent ambiguity errors when signed and unsigned integers are compared.
-    inline long min(long x, long y) {return std::min(x, y);}  
-    inline long max(long x, long y) {return std::max(x, y);}
-  }
-
-#else // defined( __SGI_STL_PORT )
-  namespace std {
-    // These overloads prevent ambiguity errors when int, long and unsigned int and int are compared.
-       
-       inline int min(int x, int y) { return x < y ? x : y; }  
-       inline int max(int x, int y) { return x > y ? x : y; }
-
-       inline unsigned int min(unsigned int x, unsigned int y) { return x < y ? x : y; }  
-       inline unsigned int max(unsigned int x, unsigned int y) { return x > y ? x : y; }
-
-       inline long min(long x, long y) { return x < y ? x : y; }  
-       inline long max(long x, long y) { return x > y ? x : y; }
-
-       inline long min(int x, long y) { return x < y ? x : y; }  
-       inline long max(int x, long y) { return x > y ? x : y; }
-
-       inline long min(long x, int y) { return x < y ? x : y; }  
-       inline long max(long x, int y) { return x > y ? x : y; }
-
-       inline unsigned long min(unsigned long x, unsigned long y) { return x < y ? x : y; }  
-       inline unsigned long max(unsigned long x, unsigned long y) { return x > y ? x : y; }
-
-       inline double min(double x, double y) { return x < y ? x : y; }  
-       inline double max(double x, double y) { return x > y ? x : y; }
-  }
-
-#endif // defined( __SGI_STL_PORT )
-
-#ifdef __cplusplus
-extern "C" {
+// -*- C++ -*-
+/**
+ * \file os_win32.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ *
+ * These classes should be used only on Windows machines.
+ */
+
+#ifndef OS_WIN32_H
+#define OS_WIN32_H
+
+#include <string>
+
+#if !defined(_WIN32)
+# error os_win32.h should be compiled only under Windows.
 #endif
 
-
-//fcntl.h
-#define FD_CLOEXEC     1       /* posix */
-#define        F_DUPFD         0       /* Duplicate fildes */
-#define        F_GETFD         1       /* Get fildes flags (close on exec) */
-#define        F_SETFD         2       /* Set fildes flags (close on exec) */
-#define        F_GETFL         3       /* Get file flags */
-#define        F_SETFL         4       /* Set file flags */
-#define O_NONBLOCK      0x4000
-inline int fcntl (int, int, ...) {return -1;}
-
-//signal.h
-#define SIGHUP 1
-#define SIGKILL 9
-
-//sys/time.h
-//struct timeval {
-//  long tv_sec;
-//  long tv_usec;
-//};
-
-//unistd.h
-inline int fork () {return -1;}
-#define pipe(a) _pipe(a,0,0)
-
-
-//sys/wait.h
-#define waitpid(a,b,c) cwait(b,a,c)
-#define WNOHANG 1
-#define WUNTRACED 2
-#define WIFEXITED(a) 0
-#define WEXITSTATUS(a) 0
-#define WIFSIGNALED(a) 0
-#define WTERMSIG(a) 0
-#define WIFSTOPPED(a) 0
-#define WSTOPSIG(a) 0
-
-//sys/types.h
-#define fd_set int
-
-//sys/select.h
-//#define select(a,b,c,d,e) -1
-#define FD_ZERO(a)
-#define FD_SET(a,b)
-#define FD_ISSET(fd, set) 0
-
-#ifndef __MINGW32__ //already defined in mingw headers
-
-#define        _S_IFBLK        0x3000
-#define        S_IFIFO         _S_IFIFO
-#define        S_IFBLK         _S_IFBLK
-#define        S_ISFIFO(m)     (((m) & S_IFMT) == S_IFIFO)
-#define        S_ISBLK(m)      (((m) & S_IFMT) == S_IFBLK)
-#define popen(a,b) _popen(a,b)
-#define pclose(a) _pclose(a)
-
-#endif //!__MINGW32
-
-#ifdef __cplusplus
-}
+/* The GetLongPathNameA function declaration in
+ * <winbase.h> is protected by the WINVER macro which is
+ * defined to a default value in <windef.h> under MinGW and Cygwin.
+ *
+ * SHGFP_TYPE_CURRENT is defined in <shlobj.h> for __W32API_VERSION >= 3.2
+ * where it is protected by _WIN32_IE, also defined to a default value
+ * in <windef.h> under MinGW and Cygwin.
+ * It is missing in earlier versions of the MinGW w32api headers.
+ *
+ * We need to #include <windows.h> now to make available the
+ * DWORD, HMODULE et al. typedefs, so first define WINVER, _WIN32_IE.
+ *
+ * Note: __CYGWIN__ can be defined here if building in _WIN32 mode.
+ */
+#if defined(__MINGW32__)  || defined(__CYGWIN__) || defined(__CYGWIN32__)
+# if defined(WINVER)
+#  if WINVER < 0x0500
+#   error WINVER must be >= 0x0500
+#  endif
+# else
+#  define WINVER 0x0500
+# endif
+# define _WIN32_IE 0x0500
 #endif
 
-#endif //_OS_WIN32_H_
+#include <windows.h>
+#include <tchar.h>
+#include <psapi.h>
+
+
+namespace lyx {
+namespace support {
+namespace os {
+
+/** Win98 and earlier don't have SHGetFolderPath in shell32.dll.
+ *  Microsoft recommend that we load shfolder.dll at run time and
+ *  access the function through that.
+ *
+ *  shfolder.dll is loaded dynamically in the constructor. If loading
+ *  fails or if the .dll is found not to contain SHGetFolderPathA then
+ *  the program exits immediately. Otherwise, the .dll is unloaded in
+ *  the destructor
+ *
+ *  The class makes SHGetFolderPath available through its function operator.
+ *  It will work on all versions of Windows >= Win95.
+ */
+class GetFolderPath {
+public:
+       enum folder_id {
+               /// CSIDL_PERSONAL
+               PERSONAL,
+               /// CSIDL_APPDATA
+               APPDATA
+       };
+
+       GetFolderPath();
+       ~GetFolderPath();
+
+       /** Wrapper for SHGetFolderPathA, returning
+        *  the path asscociated with @c id in utf8 encoding.
+        */
+       std::string const operator()(folder_id id) const;
+private:
+       typedef HRESULT (__stdcall * function_pointer)(HWND, int, HANDLE, DWORD, LPCSTR);
+
+       HMODULE folder_module_;
+       function_pointer folder_path_func_;
+};
+
+} // namespace os
+} // namespace support
+} // namespace lyx
+
+#endif // OS_WIN32_H