aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/wx/c_src/wxe_driver.h1
-rw-r--r--lib/wx/c_src/wxe_impl.cpp83
-rw-r--r--lib/wx/c_src/wxe_ps_init.c59
3 files changed, 70 insertions, 73 deletions
diff --git a/lib/wx/c_src/wxe_driver.h b/lib/wx/c_src/wxe_driver.h
index c765c866c2..0f0143bd4c 100644
--- a/lib/wx/c_src/wxe_driver.h
+++ b/lib/wx/c_src/wxe_driver.h
@@ -67,6 +67,7 @@ void push_command(int op,char * buf,int len, wxe_data *);
void meta_command(int what, wxe_data *sd);
void * wxe_ps_init();
+void * wxe_ps_init2();
extern ErlDrvPort WXE_DRV_PORT_HANDLE;
extern ErlDrvTermData WXE_DRV_PORT;
diff --git a/lib/wx/c_src/wxe_impl.cpp b/lib/wx/c_src/wxe_impl.cpp
index adfee8da73..8adec4be07 100644
--- a/lib/wx/c_src/wxe_impl.cpp
+++ b/lib/wx/c_src/wxe_impl.cpp
@@ -23,6 +23,10 @@
#include <wx/wx.h>
+#if defined(_WIN32)
+#include <wx/msw/private.h> // for wxSetInstance
+#endif
+
// Avoid including these in dcbuffer below
#include "wx/dcmemory.h"
#include "wx/dcclient.h"
@@ -31,10 +35,6 @@
#define private public
#include <wx/dcbuffer.h>
-#if defined(__WXMSW__)
- #include <wx/msw/private.h> // for wxSetInstance
-#endif
-
#undef private
#include "wxe_impl.h"
@@ -221,19 +221,18 @@ void *wxe_main_loop(void *vpdl)
driver_pdl_inc_refc(pdl);
- // ErlDrvSysInfo einfo;
- // driver_system_info(&einfo, sizeof(ErlDrvSysInfo));
// Disable floating point execption if they are on.
// This should be done in emulator but it's not in yet.
#ifndef _WIN32
erts_thread_disable_fpe();
-#else
- // Setup that wxWidgets should look for cursors and icons in
- // this dll and not in werl.exe (which is the default)
- HMODULE WXEHandle = GetModuleHandle(_T("wxe_driver"));
- wxSetInstance((HINSTANCE) WXEHandle);
+#else
+ // Setup that wxWidgets should look for cursors and icons in
+ // this dll and not in werl.exe (which is the default)
+ HMODULE WXEHandle = GetModuleHandle(_T("wxe_driver"));
+ wxSetInstance((HINSTANCE) WXEHandle);
#endif
+ wxe_ps_init();
result = wxEntry(argc, argv);
// fprintf(stderr, "WXWidgets quits main loop %d \r\n", result);
if(result >= 0 && wxe_status == WXE_INITIATED) {
@@ -254,68 +253,46 @@ void *wxe_main_loop(void *vpdl)
}
}
-wxFrame * dummy_window;
-
-void create_dummy_window() {
- dummy_window = new wxFrame(NULL,-1, wxT("wx driver"),
- wxPoint(0,0), wxSize(5,5),
- wxFRAME_NO_TASKBAR);
-
- wxMenuBar * menubar = new wxMenuBar();
- dummy_window->SetMenuBar(menubar);
- // wx-2.9 Don't delete the app menubar correctly
- dummy_window->Connect(wxID_ANY, wxEVT_CLOSE_WINDOW,
- (wxObjectEventFunction) (wxEventFunction) &WxeApp::dummy_close);
- dummy_window->Connect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
- (wxObjectEventFunction) (wxEventFunction) &WxeApp::dummy_close);
- dummy_window->Show(true);
- // dummy_window->Show(false);
-}
-
-// wxMac really wants a top level window which command-q quits if there are no
-// windows open, and this will kill the thread, so restart the dummy_window each
-// time a we receive a close.
void WxeApp::dummy_close(wxEvent& Ev) {
- if(Ev.GetEventType() == wxEVT_CLOSE_WINDOW) {
- create_dummy_window();
- }
+ // fprintf(stderr, "Dummy Close invoked\r\n");
+ // wxMac really wants a top level window which command-q quits if there are no
+ // windows open, and this will kill the erlang, override default handling
}
// Init wx-widgets thread
bool WxeApp::OnInit()
{
- wxe_ps_init();
global_me = new wxeMemEnv();
wxe_batch = new wxList;
wxe_batch_cb_saved = new wxList;
cb_buff = NULL;
- // wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED); Hmm printpreview doesn't work in 2.9 with this
+ wxe_ps_init2();
+ // wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED); // Hmm printpreview doesn't work in 2.9 with this
- this->Connect(wxID_ANY, wxEVT_IDLE,
- (wxObjectEventFunction) (wxEventFunction) &WxeApp::idle);
- this->Connect(CREATE_PORT, wxeEVT_META_COMMAND,
- (wxObjectEventFunction) (wxEventFunction) &WxeApp::newMemEnv);
- this->Connect(DELETE_PORT, wxeEVT_META_COMMAND,
- (wxObjectEventFunction) (wxEventFunction) &WxeApp::destroyMemEnv);
- this->Connect(WXE_SHUTDOWN, wxeEVT_META_COMMAND,
- (wxObjectEventFunction) (wxEventFunction) &WxeApp::shutdown);
+ Connect(wxID_ANY, wxEVT_IDLE, (wxObjectEventFunction) (wxEventFunction) &WxeApp::idle);
+ Connect(CREATE_PORT, wxeEVT_META_COMMAND,(wxObjectEventFunction) (wxEventFunction) &WxeApp::newMemEnv);
+ Connect(DELETE_PORT, wxeEVT_META_COMMAND,(wxObjectEventFunction) (wxEventFunction) &WxeApp::destroyMemEnv);
+ Connect(WXE_SHUTDOWN, wxeEVT_META_COMMAND,(wxObjectEventFunction) (wxEventFunction) &WxeApp::shutdown);
// fprintf(stderr, "Size void* %d: long %d long long %d int64 %d \r\n",
// sizeof(void *), sizeof(long), sizeof(long long), sizeof(wxInt64));
initEventTable();
wxInitAllImageHandlers();
- /* Create a dummy window so wxWidgets don't automagicly quits the main loop
- after the last window */
-#ifdef __DARWIN__
- create_dummy_window();
-#else
- SetExitOnFrameDelete(false);
+#ifdef _MACOSX
+ /* Create a default MenuBar so that we can intercept the quit command */
+ wxMenuBar *macMB = new wxMenuBar;
+ wxMenuBar::MacSetCommonMenuBar(macMB);
+ macMB->MacInstallMenuBar();
+ macMB->Connect(wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
+ (wxObjectEventFunction) (wxEventFunction) &WxeApp::dummy_close);
#endif
+ SetExitOnFrameDelete(false);
+
init_nonconsts(global_me, init_caller);
erl_drv_mutex_lock(wxe_status_m);
wxe_status = WXE_INITIATED;
@@ -325,9 +302,6 @@ bool WxeApp::OnInit()
}
void WxeApp::shutdown(wxeMetaCommand& Ecmd) {
-#ifdef __DARWIN__
- delete dummy_window;
-#endif
ExitMainLoop();
}
@@ -367,6 +341,7 @@ void handle_event_callback(ErlDrvPort port, ErlDrvTermData process)
// Called by wx thread
void WxeApp::idle(wxIdleEvent& event) {
+ event.Skip(true);
dispatch_cmds();
}
diff --git a/lib/wx/c_src/wxe_ps_init.c b/lib/wx/c_src/wxe_ps_init.c
index 541d188098..7c3e820e40 100644
--- a/lib/wx/c_src/wxe_ps_init.c
+++ b/lib/wx/c_src/wxe_ps_init.c
@@ -19,6 +19,7 @@
#include <stdio.h>
#include "wxe_driver.h"
+
/* Platform specific initialisation stuff */
#ifdef _MACOSX
@@ -30,34 +31,54 @@ extern OSErr CPSSetProcessName (ProcessSerialNumber *psn, char *processname);
void * wxe_ps_init()
{
ProcessSerialNumber psn;
- NSAutoreleasePool *pool;
// Enable GUI
- GetCurrentProcess(&psn);
- char *app_title = getenv("WX_APP_TITLE");
- // Undocumented function (but no documented way of doing this exists)
- CPSSetProcessName(&psn, app_title?app_title:"Erlang");
- TransformProcessType(&psn, kProcessTransformToForegroundApplication);
- SetFrontProcess(&psn);
- // Enable Cocoa calls from Carbon app
- NSApplicationLoad();
+ if(!GetCurrentProcess(&psn)) {
+ TransformProcessType(&psn, kProcessTransformToForegroundApplication);
+ SetFrontProcess(&psn);
+ }
+ return (void *) 0;
+}
+
+int is_packaged_app() {
+ // Can get lost in when execing around, we use the name instead
+ /* if(mainBundle) { */
+ /* return (CFBundleGetValueForInfoDictionaryKey(mainBundle, CFSTR("CFBundlePackageType")) != nil); */
+ /* } */
+ NSString * appName = [[NSRunningApplication currentApplication] localizedName];
+ return (strncmp("beam", [appName UTF8String], 4) != 0);
+}
+
+void * wxe_ps_init2() {
+ NSAutoreleasePool *pool;
+ ProcessSerialNumber psn;
// Setup and enable gui
pool = [[NSAutoreleasePool alloc] init];
-
- NSApplication *app = [NSApplication sharedApplication];
- // Load and set icon
- NSMutableString *file = [[NSMutableString alloc] init];
- [file appendFormat:@"%s/%s", erl_wx_privdir, "erlang-logo64.png"];
- NSImage *icon = [[NSImage alloc] initWithContentsOfFile: file];
- [app setApplicationIconImage: icon];
+ if( !is_packaged_app() ) {
+ // Undocumented function (but no documented way of doing this exists)
+ char *app_title = getenv("WX_APP_TITLE");
+ if(!GetCurrentProcess(&psn)) {
+ CPSSetProcessName(&psn, app_title?app_title:"Erlang");
+ }
+ // Load and set icon
+ NSMutableString *file = [[NSMutableString alloc] init];
+ [file appendFormat:@"%s/%s", erl_wx_privdir, "erlang-logo64.png"];
+ NSImage *icon = [[NSImage alloc] initWithContentsOfFile: file];
+ [NSApp setApplicationIconImage: icon];
+ };
- return (void *) pool;
+ return pool;
}
+
/* _MACOSX */
#else
-void * wxe_ps_init()
+void * wxe_ps_init()
+{
+ return (void *) 0;
+}
+void * wxe_ps_init2()
{
return (void *) 0;
}
-#endif
+#endif