X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Fos_win32.h;h=42016f7094eb7f33abe56afd7fb77b4fdcd8d5ee;hb=5608f6fdb67b86b4cf3d9215d24d7734239ad05a;hp=7ee35d09eabd449493baf6390fff5583ff9eeab2;hpb=3b06b2be4fbbbdc904e2a9e30e838b9f7237b3f2;p=lyx.git diff --git a/src/support/os_win32.h b/src/support/os_win32.h index 7ee35d09ea..42016f7094 100644 --- a/src/support/os_win32.h +++ b/src/support/os_win32.h @@ -1,119 +1,96 @@ -// os_win32.h copyright "Ruurd A. Reitsma" - -#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 - -// 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 + +#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 + * is protected by the WINVER macro which is + * defined to a default value in under MinGW and Cygwin. + * + * SHGFP_TYPE_CURRENT is defined in for __W32API_VERSION >= 3.2 + * where it is protected by _WIN32_IE, also defined to a default value + * in under MinGW and Cygwin. + * It is missing in earlier versions of the MinGW w32api headers. + * + * We need to #include 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 +#include +#include + + +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