2009-01-24 00:41:01 +00:00
|
|
|
/* ASE - Allegro Sprite Editor
|
|
|
|
* Copyright (C) 2001-2009 David Capello
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <allegro.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "jinete/jmutex.h"
|
|
|
|
#include "jinete/jstring.h"
|
|
|
|
#include "jinete/jwindow.h"
|
|
|
|
|
|
|
|
#include "commands/commands.h"
|
2009-10-09 01:34:06 +00:00
|
|
|
#include "commands/params.h"
|
2009-01-24 00:41:01 +00:00
|
|
|
#include "core/app.h"
|
2009-10-09 01:34:06 +00:00
|
|
|
#include "ui_context.h"
|
2009-01-24 00:41:01 +00:00
|
|
|
|
|
|
|
#ifdef ALLEGRO_WINDOWS
|
|
|
|
#include <winalleg.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ALLEGRO_WINDOWS
|
|
|
|
|
|
|
|
static WNDPROC base_wnd_proc = NULL;
|
2009-08-05 01:53:02 +00:00
|
|
|
static std::vector<jstring>* dropped_files;
|
2009-01-24 00:41:01 +00:00
|
|
|
static JMutex dropped_files_mutex;
|
|
|
|
|
|
|
|
static void subclass_hwnd();
|
|
|
|
static void unsubclass_hwnd();
|
|
|
|
static LRESULT ase_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
|
|
|
|
|
|
|
|
void install_drop_files()
|
|
|
|
{
|
2009-08-05 01:53:02 +00:00
|
|
|
dropped_files = new std::vector<jstring>();
|
2009-01-24 00:41:01 +00:00
|
|
|
dropped_files_mutex = jmutex_new();
|
|
|
|
|
|
|
|
subclass_hwnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
void uninstall_drop_files()
|
|
|
|
{
|
|
|
|
unsubclass_hwnd();
|
2009-07-27 03:15:31 +00:00
|
|
|
|
2009-01-24 00:41:01 +00:00
|
|
|
jmutex_free(dropped_files_mutex);
|
|
|
|
dropped_files_mutex = NULL;
|
2009-07-27 03:15:31 +00:00
|
|
|
|
2009-08-05 01:53:02 +00:00
|
|
|
delete dropped_files;
|
2009-01-24 00:41:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void check_for_dropped_files()
|
|
|
|
{
|
|
|
|
if (!base_wnd_proc) // drop-files hook not installed
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!jwindow_is_toplevel(app_get_top_window()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
jmutex_lock(dropped_files_mutex);
|
2009-08-05 01:53:02 +00:00
|
|
|
if (!dropped_files->empty()) {
|
|
|
|
std::vector<jstring> files = *dropped_files;
|
|
|
|
dropped_files->clear();
|
2009-01-24 00:41:01 +00:00
|
|
|
|
|
|
|
// open all files
|
2009-10-09 01:34:06 +00:00
|
|
|
|
|
|
|
Command* cmd_open_file =
|
|
|
|
CommandsModule::instance()->get_command_by_name(CommandId::open_file);
|
|
|
|
Params params;
|
|
|
|
|
|
|
|
for (std::vector<jstring>::iterator
|
|
|
|
it = files.begin(); it != files.end(); ++it) {
|
|
|
|
params.set("filename", it->c_str());
|
|
|
|
UIContext::instance()->execute_command(cmd_open_file, ¶ms);
|
|
|
|
}
|
2009-01-24 00:41:01 +00:00
|
|
|
}
|
|
|
|
jmutex_unlock(dropped_files_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void subclass_hwnd()
|
|
|
|
{
|
|
|
|
HWND hwnd = win_get_window();
|
|
|
|
|
|
|
|
// add the WS_EX_ACCEPTFILES
|
|
|
|
SetWindowLong(hwnd, GWL_EXSTYLE,
|
|
|
|
GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_ACCEPTFILES);
|
|
|
|
|
|
|
|
// set the GWL_WNDPROC to globalWndProc
|
|
|
|
base_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)ase_wnd_proc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unsubclass_hwnd()
|
|
|
|
{
|
|
|
|
HWND hwnd = win_get_window();
|
|
|
|
|
|
|
|
// restore the old wndproc
|
|
|
|
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)base_wnd_proc);
|
|
|
|
base_wnd_proc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT ase_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
|
|
|
switch (msg) {
|
|
|
|
|
|
|
|
case WM_DROPFILES:
|
|
|
|
jmutex_lock(dropped_files_mutex);
|
|
|
|
{
|
|
|
|
HDROP hdrop = (HDROP)(wparam);
|
|
|
|
int index, count, length;
|
|
|
|
|
|
|
|
count = DragQueryFile(hdrop, 0xFFFFFFFF, NULL, 0);
|
|
|
|
for (index=0; index<count; ++index) {
|
|
|
|
length = DragQueryFile(hdrop, index, NULL, 0);
|
|
|
|
if (length > 0) {
|
|
|
|
TCHAR* lpstr = new TCHAR[length+1];
|
|
|
|
DragQueryFile(hdrop, index, lpstr, length+1);
|
2009-08-05 01:53:02 +00:00
|
|
|
dropped_files->push_back(lpstr);
|
2009-01-24 00:41:01 +00:00
|
|
|
delete[] lpstr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DragFinish(hdrop);
|
|
|
|
}
|
|
|
|
jmutex_unlock(dropped_files_mutex);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
return (*base_wnd_proc)(hwnd, msg, wparam, lparam);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
void install_drop_files() { }
|
|
|
|
void uninstall_drop_files() { }
|
|
|
|
void check_for_dropped_files() { }
|
|
|
|
|
|
|
|
#endif
|