From 2622f86eb6f61c03d66371ee0bf749aa9b9a836b Mon Sep 17 00:00:00 2001 From: Soren Jorvang Date: Sun, 30 Jan 2011 14:20:20 +0000 Subject: [PATCH] Be more flexible about hotkey modifier permutations. Open .ini files with TextEdit on OS X since wx has no binding. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6986 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Src/ConfigManager.cpp | 4 +- Source/Core/DolphinWX/Src/FrameTools.cpp | 23 ++++++--- Source/Core/DolphinWX/Src/HotkeyDlg.cpp | 2 +- Source/Core/DolphinWX/Src/ISOProperties.cpp | 11 ++++ Source/Core/DolphinWX/Src/MainNoGUI.cpp | 51 ++++++++----------- Source/Core/DolphinWX/Src/WXInputBase.cpp | 31 ++++++----- Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp | 3 +- 7 files changed, 72 insertions(+), 53 deletions(-) diff --git a/Source/Core/Core/Src/ConfigManager.cpp b/Source/Core/Core/Src/ConfigManager.cpp index a1a0e2c3bb..755d79358f 100644 --- a/Source/Core/Core/Src/ConfigManager.cpp +++ b/Source/Core/Core/Src/ConfigManager.cpp @@ -32,19 +32,19 @@ static const struct { const int DefaultModifier; } g_HKData[] = { #ifdef __APPLE__ - { "ToggleFullscreen", 70 /* 'F' */, 0x08 /* wxMOD_CMD */ }, { "PlayPause", 80 /* 'P' */, 0x08 /* wxMOD_CMD */ }, { "Stop", 87 /* 'W' */, 0x08 /* wxMOD_CMD */ }, { "Screenshot", 83 /* 'S' */, 0x08 /* wxMOD_CMD */ }, + { "ToggleFullscreen", 70 /* 'F' */, 0x08 /* wxMOD_CMD */ }, { "Wiimote1Connect", 49 /* '1' */, 0x08 /* wxMOD_CMD */ }, { "Wiimote2Connect", 50 /* '2' */, 0x08 /* wxMOD_CMD */ }, { "Wiimote3Connect", 51 /* '3' */, 0x08 /* wxMOD_CMD */ }, { "Wiimote4Connect", 52 /* '4' */, 0x08 /* wxMOD_CMD */ }, #else - { "ToggleFullscreen", 13 /* WXK_RETURN */, 0x01 /* wxMOD_ALT */ }, { "PlayPause", 349 /* WXK_F10 */, 0x00 /* wxMOD_NONE*/ }, { "Stop", 27 /* WXK_ESCAPE */, 0x00 /* wxMOD_NONE*/ }, { "Screenshot", 348 /* WXK_F9 */, 0x00 /* wxMOD_NONE*/ }, + { "ToggleFullscreen", 13 /* WXK_RETURN */, 0x01 /* wxMOD_ALT */ }, { "Wiimote1Connect", 344 /* WXK_F5 */, 0x01 /* wxMOD_ALT */ }, { "Wiimote2Connect", 345 /* WXK_F6 */, 0x01 /* wxMOD_ALT */ }, { "Wiimote3Connect", 346 /* WXK_F7 */, 0x01 /* wxMOD_ALT */ }, diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index 3b4c723812..2e25f2277d 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -308,7 +308,12 @@ void CFrame::CreateMenu() wxString CFrame::GetMenuLabel(int Id) { - wxString Label; + int hotkey = SConfig::GetInstance().\ + m_LocalCoreStartupParameter.iHotkey[Id]; + int hotkeymodifier = SConfig::GetInstance().\ + m_LocalCoreStartupParameter.iHotkeyModifier[Id]; + wxString Hotkey, Label, Modifier; + switch (Id) { case HK_FULLSCREEN: @@ -335,14 +340,20 @@ wxString CFrame::GetMenuLabel(int Id) break; } - wxString Modifier = InputCommon::WXKeymodToString - (SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkeyModifier[Id]); - wxString Hotkey = InputCommon::WXKeyToString - (SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkey[Id]); + // wxWidgets only accepts Ctrl/Alt/Shift as menu accelerator + // modifiers. On OS X, "Ctrl+" is mapped to the Command key. +#ifdef __APPLE__ + if (hotkeymodifier & wxMOD_CMD) + hotkeymodifier |= wxMOD_CONTROL; +#endif + hotkeymodifier &= wxMOD_CONTROL | wxMOD_ALT | wxMOD_SHIFT; + + Modifier = InputCommon::WXKeymodToString(hotkeymodifier); + Hotkey = InputCommon::WXKeyToString(hotkey); if (Modifier.Len() + Hotkey.Len() > 0) Label += '\t'; - return Label + Modifier + (Modifier.Len() ? _T("+") : _T("")) + Hotkey; + return Label + Modifier + Hotkey; } diff --git a/Source/Core/DolphinWX/Src/HotkeyDlg.cpp b/Source/Core/DolphinWX/Src/HotkeyDlg.cpp index 6a29ae83fb..08da70edb5 100644 --- a/Source/Core/DolphinWX/Src/HotkeyDlg.cpp +++ b/Source/Core/DolphinWX/Src/HotkeyDlg.cpp @@ -117,7 +117,7 @@ void HotkeyConfigDialog::OnKeyDown(wxKeyEvent& event) // Update the textbox for the buttons void HotkeyConfigDialog::SetButtonText(int id, const wxString &keystr, const wxString &modkeystr) { - m_Button_Hotkeys[id]->SetLabel(modkeystr + (modkeystr.Len() ? _T("+") : _T("")) + keystr); + m_Button_Hotkeys[id]->SetLabel(modkeystr + keystr); } void HotkeyConfigDialog::DoGetButtons(int _GetId) diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index 3a272ec5f9..d6f709451c 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -15,6 +15,10 @@ // Official SVN repository and contact information can be found at // http://code.google.com/p/dolphin-emu/ +#ifdef __APPLE__ +#import +#endif + #include "Common.h" #include "CommonPaths.h" #include "Globals.h" @@ -1129,6 +1133,12 @@ void CISOProperties::OnEditConfig(wxCommandEvent& WXUNUSED (event)) { SaveGameConfig(); +#ifdef __APPLE__ + // wxTheMimeTypesManager is not yet implemented for wxCocoa + [[NSWorkspace sharedWorkspace] openFile: + [NSString stringWithUTF8String: GameIniFile.c_str()] + withApplication: @"TextEdit"]; +#else wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension(_T("ini")); if(filetype == NULL) // From extension failed, trying with MIME type now { @@ -1146,6 +1156,7 @@ void CISOProperties::OnEditConfig(wxCommandEvent& WXUNUSED (event)) else if(wxExecute(OpenCommand, wxEXEC_SYNC) == -1) PanicAlertT("wxExecute returned -1 on application run!"); +#endif GameIni.Load(GameIniFile.c_str()); LoadGameConfig(); diff --git a/Source/Core/DolphinWX/Src/MainNoGUI.cpp b/Source/Core/DolphinWX/Src/MainNoGUI.cpp index 798f6027f7..bb8bc67de5 100644 --- a/Source/Core/DolphinWX/Src/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/Src/MainNoGUI.cpp @@ -259,11 +259,6 @@ void X11_MainLoop() int main(int argc, char* argv[]) { -#ifdef __APPLE__ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSEvent *event = [[NSEvent alloc] init]; - ProcessSerialNumber psn; -#endif int ch, help = 0; struct option longopts[] = { { "exec", no_argument, NULL, 'e' }, @@ -307,36 +302,32 @@ int main(int argc, char* argv[]) if (BootManager::BootCore(argv[optind])) { #ifdef __APPLE__ - GetCurrentProcess(&psn); - TransformProcessType(&psn, kProcessTransformToForegroundApplication); - SetFrontProcess(&psn); - - if (NSApp == nil) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSEvent *event = [[NSEvent alloc] init]; [NSApplication sharedApplication]; - //TODO : Create menu + [NSApp activateIgnoringOtherApps: YES]; [NSApp finishLaunching]; - } - while (running) - { - event = [NSApp nextEventMatchingMask: NSAnyEventMask - untilDate: [NSDate distantFuture] - inMode: NSDefaultRunLoopMode dequeue: YES]; - - if ([event type] == NSKeyDown && - [event modifierFlags] & NSCommandKeyMask && - [[event characters] UTF8String][0] == 'q') + while (running) { - Core::Stop(); - break; - } + event = [NSApp nextEventMatchingMask: NSAnyEventMask + untilDate: [NSDate distantFuture] + inMode: NSDefaultRunLoopMode dequeue: YES]; + + if ([event type] == NSKeyDown && + [event modifierFlags] & NSCommandKeyMask && + [[event characters] UTF8String][0] == 'q') + { + Core::Stop(); + break; + } + + if ([event type] != NSKeyDown) + [NSApp sendEvent: event]; + } - if ([event type] != NSKeyDown) - [NSApp sendEvent: event]; - } - - [event release]; - [pool release]; + [event release]; + [pool release]; #elif defined HAVE_X11 && HAVE_X11 XInitThreads(); X11_MainLoop(); diff --git a/Source/Core/DolphinWX/Src/WXInputBase.cpp b/Source/Core/DolphinWX/Src/WXInputBase.cpp index 96deb64422..3ed7f60ecd 100644 --- a/Source/Core/DolphinWX/Src/WXInputBase.cpp +++ b/Source/Core/DolphinWX/Src/WXInputBase.cpp @@ -138,22 +138,29 @@ const wxString WXKeyToString(int keycode) return wxString((wxChar)keycode, 1); } - return _T(""); + return wxT(""); } const wxString WXKeymodToString(int modifier) { - switch (modifier) - { - case wxMOD_ALT: return wxT("Alt"); - case wxMOD_CONTROL: return wxT("Ctrl"); - case wxMOD_ALTGR: return wxT("Ctrl+Alt"); - case wxMOD_SHIFT: return wxT("Shift"); - // wxWidgets can only use Alt/Ctrl/Shift as menu accelerators, - // so Meta (Command on OS X) is simply made equivalent to Ctrl. - case wxMOD_META: return wxT("Ctrl"); - default: return wxT(""); - } + wxString mods; + + if (modifier & wxMOD_META) +#ifdef __APPLE__ + mods += wxT("Cmd+"); +#elif defined _WIN32 + mods += wxT("Win+"); +#else + mods += wxT("Meta+"); +#endif + if (modifier & wxMOD_CONTROL) + mods += wxT("Ctrl+"); + if (modifier & wxMOD_ALT) + mods += wxT("Alt+"); + if (modifier & wxMOD_SHIFT) + mods += wxT("Shift+"); + + return mods; } } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index 28a0453ea3..936b27c153 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -68,8 +68,7 @@ void OpenGL_SetWindowText(const char *text) #if defined(USE_WX) && USE_WX // Handled by Host_UpdateTitle() #elif defined(__APPLE__) - [GLWin.cocoaWin setTitle: [[[NSString alloc] - initWithCString: text] autorelease]]; + [GLWin.cocoaWin setTitle: [NSString stringWithUTF8String: text]]; #elif defined(_WIN32) // TODO convert text to unicode and change SetWindowTextA to SetWindowText SetWindowTextA(EmuWindow::GetWnd(), text);