Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ThomasWilshaw
Copy link

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

file_list[i] = (char*)malloc(MAX_PATH * sizeof(char));
strcpy_s(file_list[i],MAX_PATH, temp_filename);
}

Copy link
Member

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];

Copy link
Member

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];

Copy link
Member

@meshula meshula left a 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);
Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Author

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 chars with WideCharToMultiByte?

Signed-off-by: Thomas Wilshaw <[email protected]>
Signed-off-by: Thomas Wilshaw <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants