Browse Source

Compiles in windows

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
980920f661
  1. 1
      WIN-packages/README.md
  2. 11
      WIN-packages/dialogs_win.h
  3. 11
      src/CMakeLists.txt
  4. 32
      src/dialogs.h
  5. 34
      src/dialogs_win.cc

1
WIN-packages/README.md

@ -1 +0,0 @@
Source code for the dll's can be found at https://github.com/cppit/dialogs

11
WIN-packages/dialogs_win.h

@ -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
};

11
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}

32
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 <memory>
#include <sstream>
#include <codecvt>
#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<wchar_t> convert_typeX;
std::wstring_convert<convert_typeX, wchar_t> converterX;
return converterX.from_bytes(str);
}
std::string ws2s(const std::wstring& wstr) {
typedef std::codecvt_utf8<wchar_t> convert_typeX;
std::wstring_convert<convert_typeX, wchar_t> 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_

34
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<wchar_t> convert_typeX;
std::wstring_convert<convert_typeX, wchar_t> converterX;
return converterX.from_bytes(str);
}
std::string WinString::ws2s(const std::wstring& wstr) {
typedef std::codecvt_utf8<wchar_t> convert_typeX;
std::wstring_convert<convert_typeX, wchar_t> 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();

Loading…
Cancel
Save