From 980920f661b906c42944caec4d56cc14e0375233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Tue, 20 Oct 2015 01:12:58 +0200 Subject: [PATCH] Compiles in windows --- WIN-packages/README.md | 1 - WIN-packages/dialogs_win.h | 11 ----------- src/CMakeLists.txt | 11 +---------- src/dialogs.h | 32 ++++---------------------------- src/dialogs_win.cc | 34 ++++++++++++++++++++++++++++++---- 5 files changed, 35 insertions(+), 54 deletions(-) delete mode 100644 WIN-packages/README.md delete mode 100644 WIN-packages/dialogs_win.h diff --git a/WIN-packages/README.md b/WIN-packages/README.md deleted file mode 100644 index 11b5099..0000000 --- a/WIN-packages/README.md +++ /dev/null @@ -1 +0,0 @@ -Source code for the dll's can be found at https://github.com/cppit/dialogs \ No newline at end of file diff --git a/WIN-packages/dialogs_win.h b/WIN-packages/dialogs_win.h deleted file mode 100644 index 37a1d37..0000000 --- a/WIN-packages/dialogs_win.h +++ /dev/null @@ -1,11 +0,0 @@ -extern "C" { -#ifndef JUCI_C_DIALOGS -#define JUCI_C_DIALOGS - __declspec(dllimport) const char* c_select_folder(); - __declspec(dllimport) const char* c_select_file(); - __declspec(dllimport) const char* c_new_file(); - __declspec(dllimport) const char* c_new_folder(); - __declspec(dllimport) const char* c_save_file(); -#endif // JUCI_C_DIALOGS -}; - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e3dab84..6448e52 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -76,13 +76,6 @@ set(source_files juci.h if(MSYS) list(APPEND source_files terminal_win.cc) list(APPEND source_files dialogs_win.cc) - set(DIALOGS_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/WIN-packages/") - # if (64 bit) - set(DIALOGS_LIBRARIES "${CMAKE_SOURCE_DIR}/WIN-packages/x64/libdialogs.dll") - message(${DIALOGS_LIBRARIES}) - # else - # set(DIALOGS_LIBRARIES "${CMAKE_SOURCE_DIR}/WIN-packages/x32/libdialogs.dll") - #TODO figure out how to do this.... else() list(APPEND source_files terminal.cc) list(APPEND source_files dialogs.cc) @@ -101,7 +94,6 @@ include_directories( ${GTKSVMM_INCLUDE_DIRS} ${LIBCLANG_INCLUDE_DIRS} ${ASPELL_INCLUDE_DIR} - ${DIALOGS_INCLUDE_DIRS} ../libclangmm/src ) @@ -126,8 +118,7 @@ target_link_libraries(${project_name} ${GTKSVMM_LIBRARIES} ${Boost_LIBRARIES} ${ASPELL_LIBRARIES} - ${DIALOGS_LIBRARIES} -# ${PYTHON_LIBRARIES} + #${PYTHON_LIBRARIES} ) # install(TARGETS ${project_name} ${module} diff --git a/src/dialogs.h b/src/dialogs.h index 9611783..086a93b 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -9,10 +9,9 @@ class Dialog { static std::string new_file(); static std::string new_folder(); static std::string save_file(); -}; // namespace Dialog +}; // Dialog #ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN #define NTDDI_VERSION NTDDI_VISTA #define _WIN32_WINNT _WIN32_WINNT_VISTA @@ -22,31 +21,6 @@ class Dialog { #include #include #include -#include "singletons.h" - -#ifndef check -HRESULT __hr__; -#define check(__fun__, error_message) \ - __hr__ = __fun__; \ - if (FAILED(__hr__)) { \ - Singleton::terminal()->print(error_message); \ - throw std::exception(error_message); - } -#endif - - -// http://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string -std::wstring s2ws(const std::string& str) { - typedef std::codecvt_utf8 convert_typeX; - std::wstring_convert converterX; - return converterX.from_bytes(str); -} - -std::string ws2s(const std::wstring& wstr) { - typedef std::codecvt_utf8 convert_typeX; - std::wstring_convert converterX; - return converterX.to_bytes(wstr); -} class WinString { public: @@ -57,6 +31,8 @@ public: wchar_t** operator&() { return &str; } private: wchar_t* str; + std::wstring s2ws(const std::string& str); + std::string ws2s(const std::wstring& wstr); }; class CommonDialog { @@ -86,5 +62,5 @@ public: add_option(option); } }; -#endif +#endif // __WIN32 #endif // JUCI_DIALOG_H_ diff --git a/src/dialogs_win.cc b/src/dialogs_win.cc index ee1b30e..d7b2791 100644 --- a/src/dialogs_win.cc +++ b/src/dialogs_win.cc @@ -1,14 +1,26 @@ #ifdef _WIN32 #include "dialogs.h" +#include "singletons.h" -// { WIN_STRING +#ifndef check +HRESULT __hr__; +#define check(__fun__, error_message) \ + __hr__ = __fun__; \ + if (FAILED(__hr__)) { \ + Singleton::terminal()->print(error_message); \ + throw std::runtime_error(error_message); \ +} +#endif // CHECK + + +// { WINSTRING WinString::WinString(const std::string &string) { std::wstringstream ss; ss << s2ws(string); ss >> str; } -WinString::operator()() { +std::string WinString::operator()() { std::string res; if (str != nullptr) { std::wstring ss(str); @@ -16,7 +28,21 @@ WinString::operator()() { } return res; } -// WIN_STRING } + +// http://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string +std::wstring WinString::s2ws(const std::string& str) { + typedef std::codecvt_utf8 convert_typeX; + std::wstring_convert converterX; + return converterX.from_bytes(str); +} + +std::string WinString::ws2s(const std::wstring& wstr) { + typedef std::codecvt_utf8 convert_typeX; + std::wstring_convert converterX; + return converterX.to_bytes(wstr); +} + +// WINSTRING } // { COMMON_DIALOG CommonDialog::CommonDialog(CLSID type) : dialog(nullptr) { @@ -39,7 +65,7 @@ std::string CommonDialog::show() { check(dialog->Show(nullptr), "Failed to show dialog"); IShellItem *result = nullptr; check(dialog->GetResult(&result), "Failed to get result from dialog"); - win_string str; + WinString str; check(result->GetDisplayName(SIGDN_FILESYSPATH, &str), "Failed to get display name from dialog"); result->Release(); return str();