diff options
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | appveyor.yml | 30 | ||||
-rw-r--r-- | src/api/win32/callback.rs | 22 | ||||
-rw-r--r-- | src/api/win32/init.rs | 3 | ||||
-rw-r--r-- | src/events.rs | 7 | ||||
-rw-r--r-- | src/lib.rs | 2 |
6 files changed, 52 insertions, 17 deletions
@@ -22,7 +22,7 @@ shared_library = "0.1.0" [build-dependencies] gl_generator = "0.0.26" -khronos_api = "0.0.6" +khronos_api = "0.0.7" [dev-dependencies] clock_ticks = "0.0.5" @@ -51,6 +51,7 @@ core-graphics = "0" [target.i686-pc-windows-gnu.dependencies] winapi = "~0.1.18" +shell32-sys = "0.1" gdi32-sys = "0.1" user32-sys = "~0.1.1" kernel32-sys = "0.1" @@ -58,6 +59,7 @@ dwmapi-sys = "0.1" [target.x86_64-pc-windows-gnu.dependencies] winapi = "~0.1.18" +shell32-sys = "0.1" gdi32-sys = "0.1" user32-sys = "~0.1.1" kernel32-sys = "0.1" @@ -65,6 +67,7 @@ dwmapi-sys = "0.1" [target.x86_64-pc-windows-msvc.dependencies] winapi = "~0.1.18" +shell32-sys = "0.1" gdi32-sys = "0.1" user32-sys = "~0.1.1" kernel32-sys = "0.1" diff --git a/appveyor.yml b/appveyor.yml index 17bad94..b3ec520 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,19 +1,21 @@ +environment: + CARGO_TARGET: x86_64-pc-windows-gnu + matrix: + - TARGET: x86_64-pc-windows-msvc + - TARGET: i686-pc-windows-gnu install: - - ps: | - if ($env:PLATFORM -eq "x86") { - Start-FileDownload 'https://static.rust-lang.org/dist/rust-1.0.0-i686-pc-windows-gnu.exe' -FileName rust.exe - } else { - Start-FileDownload 'https://static.rust-lang.org/dist/rust-1.0.0-x86_64-pc-windows-gnu.exe' -FileName rust.exe - } - - rust.exe /VERYSILENT /NORESTART /DIR="C:\Program Files\Rust" - - SET PATH=%PATH%;C:\Program Files\Rust\bin - - rustc -vV + - ps: Start-FileDownload "https://static.rust-lang.org/dist/rustc-nightly-${env:TARGET}.tar.gz" + - ps: Start-FileDownload "https://static.rust-lang.org/cargo-dist/cargo-nightly-${env:CARGO_TARGET}.tar.gz" + - 7z x rustc-nightly-%TARGET%.tar.gz > nul + - 7z x rustc-nightly-%TARGET%.tar > nul + - 7z x cargo-nightly-%CARGO_TARGET%.tar.gz > nul + - 7z x cargo-nightly-%CARGO_TARGET%.tar > nul + - call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64 + - set PATH=%PATH%;%cd%/rustc-nightly-%TARGET%/rustc/bin + - set PATH=%PATH%;%cd%/cargo-nightly-%CARGO_TARGET%/cargo/bin + - SET PATH=%PATH%;C:\MinGW\bin + - rustc -V - cargo -V - - git submodule update --init --recursive - -platform: - - x86 - - x64 build: false diff --git a/src/api/win32/callback.rs b/src/api/win32/callback.rs index 6ac56f3..25beb7b 100644 --- a/src/api/win32/callback.rs +++ b/src/api/win32/callback.rs @@ -3,12 +3,15 @@ use std::ptr; use std::cell::RefCell; use std::sync::mpsc::Sender; use std::sync::{Arc, Mutex}; +use std::ffi::OsString; +use std::os::windows::ffi::OsStringExt; use CursorState; use Event; use super::event; use user32; +use shell32; use winapi; /// There's no parameters passed to the callback function, so it needs to get @@ -249,6 +252,25 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, 0 }, + winapi::WM_DROPFILES => { + use events::Event::DroppedFile; + + let hdrop = wparam as winapi::HDROP; + let mut pathbuf: [u16; winapi::MAX_PATH] = unsafe { mem::uninitialized() }; + let num_drops = shell32::DragQueryFileW(hdrop, 0xFFFFFFFF, ptr::null_mut(), 0); + + for i in 0..num_drops { + let nch = shell32::DragQueryFileW(hdrop, i, pathbuf.as_mut_ptr(), + winapi::MAX_PATH as u32) as usize; + if nch > 0 { + send_event(window, DroppedFile(OsString::from_wide(&pathbuf[0..nch]).into())); + } + } + + shell32::DragFinish(hdrop); + 0 + }, + _ => { user32::DefWindowProcW(window, msg, wparam, lparam) } diff --git a/src/api/win32/init.rs b/src/api/win32/init.rs index 7cb5433..cc6d2d2 100644 --- a/src/api/win32/init.rs +++ b/src/api/win32/init.rs @@ -133,7 +133,8 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>, style | winapi::WS_VISIBLE }; - let handle = user32::CreateWindowExW(ex_style, class_name.as_ptr(), + let handle = user32::CreateWindowExW(ex_style | winapi::WS_EX_ACCEPTFILES, + class_name.as_ptr(), title.as_ptr() as winapi::LPCWSTR, style | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN, x.unwrap_or(winapi::CW_USEDEFAULT), y.unwrap_or(winapi::CW_USEDEFAULT), diff --git a/src/events.rs b/src/events.rs index cff58e9..2fcdc61 100644 --- a/src/events.rs +++ b/src/events.rs @@ -1,4 +1,6 @@ -#[derive(Clone, Debug, Copy)] +use std::path::PathBuf; + +#[derive(Clone, Debug)] pub enum Event { /// The size of the window has changed. Resized(u32, u32), @@ -9,6 +11,9 @@ pub enum Event { /// The window has been closed. Closed, + /// A file has been dropped into the window. + DroppedFile(PathBuf), + /// The window received a unicode character. ReceivedCharacter(char), @@ -37,6 +37,8 @@ extern crate winapi; #[cfg(target_os = "windows")] extern crate kernel32; #[cfg(target_os = "windows")] +extern crate shell32; +#[cfg(target_os = "windows")] extern crate gdi32; #[cfg(target_os = "windows")] extern crate user32; |