From 4363187d4e86c63d9465cbe7296d11fdc7815e32 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 17 Feb 2017 15:00:52 +0100 Subject: Replace obsolete WIN32 ifdefs with platform define. --- configure.ac | 8 ++++---- plugin/drumgizmo_plugin.h | 9 --------- plugingui/Makefile.mingw32 | 2 +- plugingui/directory.cc | 22 ++++++++++++---------- plugingui/filebrowser.cc | 7 ++++--- plugingui/filebrowser.h | 6 ++++-- plugingui/testmain.cc | 2 +- plugingui/tests/resizetest.cc | 2 +- plugingui/tests/tabwidgettest.cc | 2 +- plugingui/window.cc | 35 ++++++++++++++++++----------------- src/configfile.cc | 10 ++++++---- src/mutex.cc | 15 ++++++++------- src/thread.cc | 31 +++++++++++++++---------------- src/thread.h | 33 ++++++++++++++++++--------------- 14 files changed, 93 insertions(+), 91 deletions(-) diff --git a/configure.ac b/configure.ac index 828cd8e..a56fd39 100644 --- a/configure.ac +++ b/configure.ac @@ -158,22 +158,22 @@ AS_IF( PKG_CHECK_MODULES(X11, x11 >= 1.0) PKG_CHECK_MODULES(XEXT, xext >= 1.0) - GUI_CPPFLAGS="-DX11 $X11_CFLAGS $XEXT_CFLAGS" + GUI_CPPFLAGS="-DUI_X11 $X11_CFLAGS $XEXT_CFLAGS" GUI_LIBS="$X11_LIBS $XEXT_LIBS"], [test "x$enable_gui" = "xwin32"], [AC_MSG_RESULT([Setting gui backend to Win32]) - GUI_CPPFLAGS="-DWIN32" + GUI_CPPFLAGS="-DUI_WIN32" GUI_LIBS="-lgdi32 -lsetupapi -lws2_32"], [test "x$enable_gui" = "xpugl"], [AC_MSG_RESULT([Setting gui backend to Pugl]) - GUI_CPPFLAGS="-DPUGL -I../../pugl" + GUI_CPPFLAGS="-DUI_PUGL -I../../pugl" GUI_LIBS="-lGLU -lGL -lglut"], [test "x$enable_gui" = "xcocoa"], [AC_MSG_RESULT([Setting gui backend to Cocoa]) - GUI_CPPFLAGS="-framework Cocoa" + GUI_CPPFLAGS="-DUI_COCOA -framework Cocoa" GUI_LIBS="-framework Cocoa"], AC_MSG_ERROR([*** No GUI backend has been selected ***]) diff --git a/plugin/drumgizmo_plugin.h b/plugin/drumgizmo_plugin.h index de4f4af..b3db7b2 100644 --- a/plugin/drumgizmo_plugin.h +++ b/plugin/drumgizmo_plugin.h @@ -28,15 +28,6 @@ #include -#if defined(X11) -#include -#endif // defined(X11) - -#if defined(WIN32) -#define WIN32_LEAN_AND_MEAN -#include -#endif // defined(WIN32) - #ifdef LV2 #include #endif diff --git a/plugingui/Makefile.mingw32 b/plugingui/Makefile.mingw32 index 50c8fad..7f5b191 100644 --- a/plugingui/Makefile.mingw32 +++ b/plugingui/Makefile.mingw32 @@ -49,7 +49,7 @@ GUI_SRC = \ resource_data.cc \ lodepng/lodepng.cpp -GUI_CFLAGS=-DUSE_THREAD -DWIN32 -DSTANDALONE +GUI_CFLAGS=-DUSE_THREAD -DUI_WIN32 -DSTANDALONE GUI_LIBS=-lgdi32 -lsetupapi -lws2_32 DBG_SRC = \ diff --git a/plugingui/directory.cc b/plugingui/directory.cc index 7515c30..96ed5b7 100644 --- a/plugingui/directory.cc +++ b/plugingui/directory.cc @@ -33,7 +33,9 @@ #include #include -#ifdef WIN32 +#include + +#if DG_PLATFORM == DG_PLATFORM_WINDOWS #include #include #endif @@ -43,7 +45,7 @@ #define DRUMKIT_SUFFIX ".xml" // http://en.wikipedia.org/wiki/Path_(computing) -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS #define SEP "\\" #else #define SEP "/" @@ -216,7 +218,7 @@ Directory::EntryList Directory::listFiles(std::string path, unsigned char filter } } -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS //DEBUG(directory, "Root is %s\n", Directory::root(path).c_str()); //DEBUG(directory, "Current path %s is root? %d", path.c_str(), // Directory::isRoot(path)); @@ -270,7 +272,7 @@ Directory::EntryList Directory::listFiles(std::string path, unsigned char filter bool Directory::isRoot(std::string path) { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS std::transform(path.begin(), path.end(), path.begin(), ::tolower); std::string root_str = Directory::root(path); std::transform(root_str.begin(), root_str.end(), root_str.begin(), ::tolower); @@ -321,7 +323,7 @@ std::string Directory::root() std::string Directory::root(std::string path) { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS if(path.size() < 2) { return "c:"; // just something default when input is bad @@ -338,7 +340,7 @@ std::string Directory::root(std::string path) Directory::DriveList Directory::drives() { Directory::DriveList drives; -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS unsigned int d = GetLogicalDrives(); for(int i = 0; i < 32; ++i) { @@ -399,7 +401,7 @@ bool Directory::exists(std::string path) bool Directory::isHidden(std::string path) { //DEBUG(directory, "Is '%s' hidden?\n", path.c_str()); -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS // We dont want to filter out '..' pointing to root of a partition unsigned pos = path.find_last_of("/\\"); std::string entry = path.substr(pos+1); @@ -518,7 +520,7 @@ std::string Directory::pathToStr(Directory::Path& path) { std::string dir = *it; //DEBUG(directory, "\tDir '%s'\n", dir.c_str()); -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS if(it != path.begin()) { cleaned_path += SEP; @@ -534,12 +536,12 @@ std::string Directory::pathToStr(Directory::Path& path) if(cleaned_path.empty()) { cleaned_path = Directory::root(); -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS cleaned_path += SEP; #endif } -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS if(cleaned_path.size() == 2) { cleaned_path += SEP; diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc index 329c599..6ac9d3e 100644 --- a/plugingui/filebrowser.cc +++ b/plugingui/filebrowser.cc @@ -39,6 +39,7 @@ #include #include +#include #include #ifdef __MINGW32__ @@ -57,7 +58,7 @@ FileBrowser::FileBrowser(Widget *parent) , btn_esc(this) , back(":bg.png") { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS above_root = false; #endif @@ -185,7 +186,7 @@ void FileBrowser::changeDir() INFO(filebrowser, "Changing path to '%s'\n", (dir.path() + dir.seperator() + value).c_str()); -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS if(above_root && !value.empty()) { dir.setPath(value + dir.seperator()); @@ -211,7 +212,7 @@ void FileBrowser::changeDir() std::vector items; -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS if(Directory::isRoot(dir.path()) && (value == "..")) { DEBUG(filebrowser, "Showing partitions...\n"); diff --git a/plugingui/filebrowser.h b/plugingui/filebrowser.h index 64ef4da..bc7170a 100644 --- a/plugingui/filebrowser.h +++ b/plugingui/filebrowser.h @@ -27,6 +27,7 @@ #pragma once #include +#include #include "widget.h" #include "button.h" @@ -36,7 +37,8 @@ #include "image.h" #include "directory.h" -namespace GUI { +namespace GUI +{ class FileBrowser : public Widget { public: @@ -59,7 +61,7 @@ private: void handleKeyEvent(); Directory dir; -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS bool above_root; bool in_root; #endif diff --git a/plugingui/testmain.cc b/plugingui/testmain.cc index 8edfd0a..b1697eb 100644 --- a/plugingui/testmain.cc +++ b/plugingui/testmain.cc @@ -48,7 +48,7 @@ int main() while(main_window.processEvents()) { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS SleepEx(50, FALSE); #else usleep(50000); diff --git a/plugingui/tests/resizetest.cc b/plugingui/tests/resizetest.cc index 2267030..f5ba01b 100644 --- a/plugingui/tests/resizetest.cc +++ b/plugingui/tests/resizetest.cc @@ -135,7 +135,7 @@ int main() while(test_window.processEvents()) { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS SleepEx(50, FALSE); #else usleep(50000); diff --git a/plugingui/tests/tabwidgettest.cc b/plugingui/tests/tabwidgettest.cc index e187fee..ca24040 100644 --- a/plugingui/tests/tabwidgettest.cc +++ b/plugingui/tests/tabwidgettest.cc @@ -155,7 +155,7 @@ int main() while(test_window.processEvents()) { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS SleepEx(50, FALSE); #else usleep(50000); diff --git a/plugingui/window.cc b/plugingui/window.cc index e2a5b58..d4046c2 100644 --- a/plugingui/window.cc +++ b/plugingui/window.cc @@ -30,19 +30,19 @@ #include "painter.h" -#ifndef PUGL -#ifdef X11 +#ifndef UI_PUGL +#ifdef UI_X11 #include "nativewindow_x11.h" -#endif/*X11*/ -#ifdef WIN32 +#endif // UI_X11 +#ifdef UI_WIN32 #include "nativewindow_win32.h" -#endif/*WIN32*/ -#ifdef COCOA +#endif // UI_WIN32 +#ifdef UI_COCOA #include "nativewindow_cocoa.h" -#endif/*COCOA*/ +#endif // UI_COCOA #else #include "nativewindow_pugl.h" -#endif +#endif // !UI_PUGL namespace GUI { @@ -55,19 +55,20 @@ Window::Window(void* native_window) _width = wpixbuf.width; _height = wpixbuf.height; -#ifndef PUGL -#ifdef X11 +#ifndef UI_PUGL +#ifdef UI_X11 native = new NativeWindowX11(native_window, *this); -#endif/*X11*/ -#ifdef WIN32 +#endif // UI_X11 +#ifdef UI_WIN32 native = new NativeWindowWin32(native_window, *this); -#endif/*WIN32*/ -#ifdef COCOA +#endif // UI_WIN32 +#ifdef UI_COCOA native = new NativeWindowCocoa(native_window, *this); -#endif/*COCOA*/ -#else/*Use pugl*/ +#endif // UI_COCOA +#else + // Use pugl native = new NativeWindowPugl(native_window, *this); -#endif +#endif // !UI_PUGL eventhandler = new EventHandler(*native, *this); } diff --git a/src/configfile.cc b/src/configfile.cc index 24f9deb..71496a0 100644 --- a/src/configfile.cc +++ b/src/configfile.cc @@ -35,7 +35,9 @@ #include #include -#ifdef WIN32 +#include "platform.h" + +#if DG_PLATFORM == DG_PLATFORM_WINDOWS #include #include #include @@ -45,7 +47,7 @@ #include -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS #define SEP "\\" #else #define SEP "/" @@ -58,7 +60,7 @@ */ static std::string getConfigPath() { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS std::string configpath; TCHAR szPath[256]; if(SUCCEEDED(SHGetFolderPath( @@ -87,7 +89,7 @@ static bool createConfigPath() { DEBUG(configfile, "No configuration exists, creating directory '%s'\n", configpath.c_str()); -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS if(mkdir(configpath.c_str()) < 0) { #else diff --git a/src/mutex.cc b/src/mutex.cc index 84143be..b90132d 100644 --- a/src/mutex.cc +++ b/src/mutex.cc @@ -28,8 +28,9 @@ #include "mutex.h" #include +#include "platform.h" -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS #include #else #include @@ -37,7 +38,7 @@ #endif struct mutex_private_t { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS HANDLE mutex; #else pthread_mutex_t mutex; @@ -47,7 +48,7 @@ struct mutex_private_t { Mutex::Mutex() { prv = new struct mutex_private_t(); -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS prv->mutex = CreateMutex(nullptr, // default security attributes FALSE, // initially not owned nullptr); // unnamed mutex @@ -58,7 +59,7 @@ Mutex::Mutex() Mutex::~Mutex() { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS CloseHandle(prv->mutex); #else pthread_mutex_destroy(&prv->mutex); @@ -74,7 +75,7 @@ Mutex::~Mutex() //! false otherwise. bool Mutex::try_lock() { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS DEBUG(mutex, "%s\n", __PRETTY_FUNCTION__); DWORD result = WaitForSingleObject(prv->mutex, 0); @@ -90,7 +91,7 @@ bool Mutex::try_lock() void Mutex::lock() { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS WaitForSingleObject(prv->mutex, // handle to mutex INFINITE); // no time-out interval #else @@ -100,7 +101,7 @@ void Mutex::lock() void Mutex::unlock() { -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS ReleaseMutex(prv->mutex); #else pthread_mutex_unlock(&prv->mutex); diff --git a/src/thread.cc b/src/thread.cc index 030c5dd..abc59a2 100644 --- a/src/thread.cc +++ b/src/thread.cc @@ -26,7 +26,6 @@ */ #include "thread.h" -#include #include Thread::Thread() @@ -37,32 +36,32 @@ Thread::~Thread() void Thread::run() { - DEBUG(thread, "Thread::run()\n"); -#ifdef WIN32 - tid = CreateThread(NULL, 0, thread_run, this, 0, NULL); + DEBUG(thread, "Thread::run()\n"); +#if DG_PLATFORM == DG_PLATFORM_WINDOWS + tid = CreateThread(NULL, 0, thread_run, this, 0, NULL); #else - pthread_create(&tid, NULL, thread_run, this); -#endif/*WIN32*/ + pthread_create(&tid, NULL, thread_run, this); +#endif } void Thread::wait_stop() { -#ifdef WIN32 - WaitForSingleObject(tid, INFINITE); +#if DG_PLATFORM == DG_PLATFORM_WINDOWS + WaitForSingleObject(tid, INFINITE); #else - pthread_join(tid, NULL); -#endif/*WIN32*/ + pthread_join(tid, NULL); +#endif } -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS DWORD WINAPI #else void* -#endif/*WIN32*/ +#endif Thread::thread_run(void *data) { - DEBUG(thread, "Thread run\n"); - Thread *t = (Thread*)data; - t->thread_main(); - return 0; + DEBUG(thread, "Thread run\n"); + Thread *t = (Thread*)data; + t->thread_main(); + return 0; } diff --git a/src/thread.h b/src/thread.h index 6d3b920..f5bf1a7 100644 --- a/src/thread.h +++ b/src/thread.h @@ -26,31 +26,34 @@ */ #pragma once -#ifdef WIN32 +#include "platform.h" + +#if DG_PLATFORM == DG_PLATFORM_WINDOWS #define WIN32_LEAN_AND_MEAN #include #else #include -#endif/*WIN32*/ +#endif -class Thread { +class Thread +{ public: - Thread(); - virtual ~Thread(); + Thread(); + virtual ~Thread(); - void run(); - void wait_stop(); + void run(); + void wait_stop(); protected: - virtual void thread_main() = 0; - + virtual void thread_main() = 0; + private: -#ifdef WIN32 +#if DG_PLATFORM == DG_PLATFORM_WINDOWS HANDLE tid{nullptr}; - static DWORD WINAPI + static DWORD WINAPI #else - pthread_t tid{0}; - static void* -#endif/*WIN32*/ - thread_run(void *data); + pthread_t tid{0}; + static void* +#endif + thread_run(void *data); }; -- cgit v1.2.3