-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add drag and drop support for Windows #83
base: main
Are you sure you want to change the base?
Add drag and drop support for Windows #83
Conversation
Signed-off-by: Thomas Wilshaw <[email protected]>
16863e5
to
e4280bd
Compare
file_list[i] = (char*)malloc(MAX_PATH * sizeof(char)); | ||
strcpy_s(file_list[i],MAX_PATH, temp_filename); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the guts here become slightly more complex
if (DragQueryFileW(hDrop, i, temp_filename, MAX_PATH)) {
// Determine the required buffer size for the multi-byte string
int buffer_size = WideCharToMultiByte(CP_UTF8, 0, temp_filename, -1, NULL, 0, NULL, NULL);
// Allocate memory for the converted file name
file_list[i] = (char*)malloc(buffer_size * sizeof(char));
// Convert wide character filename to UTF-8
WideCharToMultiByte(CP_UTF8, 0, temp_filename, -1, file_list[i], buffer_size, NULL, NULL);
}
char** file_list; | ||
file_list = (char**)malloc(count * sizeof(char*)); | ||
char temp_filename[MAX_PATH]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
wchar_t temp_filename[MAX_PATH];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very cool, thanks :) Small request though.
break; | ||
case WM_DROPFILES: | ||
HDROP hDrop = reinterpret_cast<HDROP>(wParam); | ||
UINT count = DragQueryFileA(hDrop, -1, NULL, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we switch this to W please, and the char** to wchar_t** as necessary? I haven't check the rest of main to find out if there's more ANSI to WIDE conversion necessary, but we could start here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both src/opentimelineio/serialization.cpp
and src/opentimelineio/deserialization.cpp
use MultiByteToWideChar()
for opening files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I right in thinking file_list
should remain as char
as we're converting UTF characters in temp_filename
into char
s with WideCharToMultiByte
?
Signed-off-by: Thomas Wilshaw <[email protected]>
35c547f
to
7e431a0
Compare
Signed-off-by: Thomas Wilshaw <[email protected]>
Signed-off-by: Thomas Wilshaw <[email protected]>
As per #57 I've added drag and drop support for Windows. It seems to work okay on basic testing but I'm always a bit iffy about C pointers so please let me know if I've messed something up there.
If you drag a single file it loads correctly but if you drag several it triggers the existing code path for loading multiple files so any changes to that should work as expected on Windows