From 459c68a6688dd547b3d92d0fafc08aea14fc5387 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Mon, 8 Jun 2015 21:27:19 -0400 Subject: [PATCH] Support for opening saves/scenarios in Windows by dropping them on the app icon --- src/boe.appleevents.mm | 4 ++-- src/boe.main.cpp | 4 ++-- src/boe.main.hpp | 2 +- src/boe.menus.win.cpp | 22 ++++++++++++++++++++++ src/pcedit/pc.appleevents.mm | 4 ++-- src/pcedit/pc.main.cpp | 6 +++--- src/pcedit/pc.menus.win.cpp | 18 ++++++++++++++++++ src/scenedit/scen.appleevents.mm | 4 ++-- src/scenedit/scen.main.cpp | 6 +++--- src/scenedit/scen.menus.win.cpp | 22 ++++++++++++++++++++++ src/tools/winutil.win.cpp | 6 ------ 11 files changed, 77 insertions(+), 21 deletions(-) diff --git a/src/boe.appleevents.mm b/src/boe.appleevents.mm index f53c651e..f6386854 100644 --- a/src/boe.appleevents.mm +++ b/src/boe.appleevents.mm @@ -29,8 +29,8 @@ typedef NSAppleEventDescriptor AEDescr; -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender; @end -void set_up_apple_events(); // Suppress "no prototype" warning -void set_up_apple_events() { +void set_up_apple_events(int argc, char* argv[]); // Suppress "no prototype" warning +void set_up_apple_events(int, char*[]) { AppleEventHandler* aeHandler = [[AppleEventHandler alloc] init]; [[NSApplication sharedApplication] setDelegate: aeHandler]; } diff --git a/src/boe.main.cpp b/src/boe.main.cpp index d61e19d8..b10d4f8d 100644 --- a/src/boe.main.cpp +++ b/src/boe.main.cpp @@ -103,7 +103,7 @@ short store_current_pc = 0; sf::Clock animTimer; -int main(int /*argc*/, char* argv[]) { +int main(int argc, char* argv[]) { #if 0 void debug_oldstructs(); debug_oldstructs(); @@ -121,7 +121,7 @@ int main(int /*argc*/, char* argv[]) { init_buf(); check_for_intel(); - set_up_apple_events(); + set_up_apple_events(argc, argv); make_cursor_watch(); plop_fancy_startup(); diff --git a/src/boe.main.hpp b/src/boe.main.hpp index ba01e53c..87246c2d 100644 --- a/src/boe.main.hpp +++ b/src/boe.main.hpp @@ -8,7 +8,7 @@ void Handle_Update(); void Mouse_Pressed(); void close_program(); void change_cursor(location where_curs); -void set_up_apple_events(); +void set_up_apple_events(int argc, char* argv[]); void move_sound(ter_num_t ter,short step); void incidental_noises(bool on_surface); void pause(short length); diff --git a/src/boe.menus.win.cpp b/src/boe.menus.win.cpp index 8a561e6f..2c7be9ce 100644 --- a/src/boe.menus.win.cpp +++ b/src/boe.menus.win.cpp @@ -312,3 +312,25 @@ LRESULT CALLBACK menuProc(HWND handle, UINT message, WPARAM wParam, LPARAM lPara } return CallWindowProc(reinterpret_cast(mainProc), handle, message, wParam, lParam); } + +#include "fileio.hpp" +#include "boe.graphics.hpp" +#include "boe.actions.hpp" +#include "boe.fileio.hpp" + +extern bool ae_loading, finished_init, startup_loaded; +void set_up_apple_events(int argc, char* argv[]) { + if(argc > 1) { + if(!load_party(argv[1], univ)) + return; + + if(!finished_init) { + ae_loading = true; + overall_mode = MODE_STARTUP; + } else finish_load_party(); + if(overall_mode != MODE_STARTUP && startup_loaded) + end_startup(); + if(overall_mode != MODE_STARTUP) + post_load(); + } +} diff --git a/src/pcedit/pc.appleevents.mm b/src/pcedit/pc.appleevents.mm index 1c9dc9cf..f7cff7d8 100644 --- a/src/pcedit/pc.appleevents.mm +++ b/src/pcedit/pc.appleevents.mm @@ -23,8 +23,8 @@ extern fs::path file_in_mem; -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender; @end -void set_up_apple_events(); // Suppress "no prototype" warning -void set_up_apple_events() { +void set_up_apple_events(int argc, char* argv[]); // Suppress "no prototype" warning +void set_up_apple_events(int, char*[]) { AppleEventHandler* aeHandler = [[AppleEventHandler alloc] init]; [[NSApplication sharedApplication] setDelegate: aeHandler]; } diff --git a/src/pcedit/pc.main.cpp b/src/pcedit/pc.main.cpp index d076e8dd..fed8c5f8 100644 --- a/src/pcedit/pc.main.cpp +++ b/src/pcedit/pc.main.cpp @@ -54,14 +54,14 @@ void Handle_Activate(); void Handle_Update(); void Mouse_Pressed(); bool verify_restore_quit(std::string dlog); -void set_up_apple_events(); +void set_up_apple_events(int argc, char* argv[]); extern bool cur_scen_is_mac; extern fs::path progDir; short specials_res_id; char start_name[256]; //MW specified return type was 'void', changed to ISO C style for Carbonisation -jmr -int main(int /*argc*/, char* argv[]) { +int main(int argc, char* argv[]) { try { init_directories(argv[0]); init_menubar(); @@ -72,7 +72,7 @@ int main(int /*argc*/, char* argv[]) { init_graph_tool(); init_snd_tool(); - set_up_apple_events(); + set_up_apple_events(argc, argv); cDialog::init(); redraw_screen(); diff --git a/src/pcedit/pc.menus.win.cpp b/src/pcedit/pc.menus.win.cpp index 1d67eb45..8530cf37 100644 --- a/src/pcedit/pc.menus.win.cpp +++ b/src/pcedit/pc.menus.win.cpp @@ -170,3 +170,21 @@ LRESULT CALLBACK menuProc(HWND handle, UINT message, WPARAM wParam, LPARAM lPara } return CallWindowProc(reinterpret_cast(mainProc), handle, message, wParam, lParam); } + +#include "fileio.hpp" +#include "pc.fileio.hpp" + +extern bool party_in_scen, scen_items_loaded; +extern fs::path file_in_mem; +void set_up_apple_events(int argc, char* argv[]) { + if(argc > 1) { + if(load_party(argv[1], univ)) { + file_in_mem = argv[1]; + party_in_scen = !univ.party.scen_name.empty(); + if(!party_in_scen) load_base_item_defs(); + scen_items_loaded = true; + update_item_menu(); + menu_activate(); + } + } +} diff --git a/src/scenedit/scen.appleevents.mm b/src/scenedit/scen.appleevents.mm index 1a44d494..0bab566a 100644 --- a/src/scenedit/scen.appleevents.mm +++ b/src/scenedit/scen.appleevents.mm @@ -27,8 +27,8 @@ extern bool change_made, ae_loading; -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*) sender; @end -void set_up_apple_events(); // Suppress "no prototype" warning -void set_up_apple_events() { +void set_up_apple_events(int argc, char* argv[]); // Suppress "no prototype" warning +void set_up_apple_events(int, char*[]) { AppleEventHandler* aeHandler = [[AppleEventHandler alloc] init]; [[NSApplication sharedApplication] setDelegate: aeHandler]; } diff --git a/src/scenedit/scen.main.cpp b/src/scenedit/scen.main.cpp index 5704b9fa..de087afb 100644 --- a/src/scenedit/scen.main.cpp +++ b/src/scenedit/scen.main.cpp @@ -54,10 +54,10 @@ cScenario scenario; rectangle right_sbar_rect; extern rectangle terrain_buttons_rect; -extern void set_up_apple_events(); +extern void set_up_apple_events(int argc, char* argv[]); //Changed to ISO C specified argument and return type. -int main(int, char* argv[]) { +int main(int argc, char* argv[]) { try { init_directories(argv[0]); @@ -75,7 +75,7 @@ int main(int, char* argv[]) { init_graph_tool(); check_for_intel(); - set_up_apple_events(); + set_up_apple_events(argc, argv); cen_x = 18; cen_y = 18; diff --git a/src/scenedit/scen.menus.win.cpp b/src/scenedit/scen.menus.win.cpp index 2d9e70f0..589af9d3 100644 --- a/src/scenedit/scen.menus.win.cpp +++ b/src/scenedit/scen.menus.win.cpp @@ -207,3 +207,25 @@ LRESULT CALLBACK menuProc(HWND handle, UINT message, WPARAM wParam, LPARAM lPara } return CallWindowProc(reinterpret_cast(mainProc), handle, message, wParam, lParam); } + +#include "fileio.hpp" +#include "scen.actions.hpp" + +extern short cur_town; +extern location cur_out; +extern cTown* town; +extern cOutdoors* current_terrain; +extern bool change_made, ae_loading; +void set_up_apple_events(int argc, char* argv[]) { + if(argc > 1) { + if(load_scenario(argv[1], scenario)) { + cur_town = scenario.last_town_edited; + town = scenario.towns[cur_town]; + cur_out = scenario.last_out_edited; + current_terrain = scenario.outdoors[cur_out.x][cur_out.y]; + change_made = false; + ae_loading = true; + set_up_main_screen(); + } + } +} diff --git a/src/tools/winutil.win.cpp b/src/tools/winutil.win.cpp index 0fb5d408..d7c72283 100644 --- a/src/tools/winutil.win.cpp +++ b/src/tools/winutil.win.cpp @@ -235,12 +235,6 @@ ModalSession::~ModalSession() { RedrawWindow(parent->getSystemHandle(), NULL, NULL, RDW_NOCHILDREN | RDW_UPDATENOW); } -void set_up_apple_events() { - // TODO: Probably nothing to do here on Windows? - // Basically what might possibly happen here is to set up stuff to handle dragging a file onto the application icon. - // The Mac version also handles requests from the operating system for the application to quit. -} - int getMenubarHeight() { return GetSystemMetrics(SM_CYMENU); }