Change away from using deprecated FSFindFolder.
list(APPEND HEADERS FGCocoaMenuBar.hxx
CocoaFileDialog.hxx
CocoaMouseCursor.hxx
- CocoaAutoreleasePool.hxx)
+ CocoaHelpers.h
+ CocoaHelpers_private.h)
list(APPEND SOURCES FGCocoaMenuBar.mm
CocoaFileDialog.mm
CocoaMouseCursor.mm
- CocoaMessageBox.mm)
+ CocoaHelpers.mm)
endif()
flightgear_component(GUI "${SOURCES}" "${HEADERS}")
+++ /dev/null
-#ifndef FG_GUI_COCOA_AUTORELEASE_POOL_HXX
-#define FG_GUI_COCOA_AUTORELEASE_POOL_HXX
-
-#include <Foundation/NSAutoreleasePool.h>
-
-class CocoaAutoreleasePool
-{
-public:
- CocoaAutoreleasePool()
- {
- pool = [[NSAutoreleasePool alloc] init];
- }
-
- ~CocoaAutoreleasePool()
- {
- [pool release];
- }
-
-private:
- NSAutoreleasePool* pool;
-};
-
-
-#endif // of FG_GUI_COCOA_AUTORELEASE_POOL_HXX
\ No newline at end of file
-// CocoaFileDialog.hxx - file dialog implemented using Cocoa
+// CocoaFileDialog.h - Cocoa implementation of file-dialog interface
+
+// Copyright (C) 2013 James Turner <zakalawe@mac.com>
+//
+// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
#ifndef FG_COCOA_FILE_DIALOG_HXX
#define FG_COCOA_FILE_DIALOG_HXX 1
+// CocoaFileDialog.mm - Cocoa implementation of file-dialog interface
+
+// Copyright (C) 2013 James Turner <zakalawe@mac.com>
+//
+// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
#include "CocoaFileDialog.hxx"
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/strutils.hxx>
+#include <GUI/CocoaHelpers_private.h>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Viewer/renderer.hxx>
-static NSString* stdStringToCocoa(const std::string& s)
-{
- return [NSString stringWithUTF8String:s.c_str()];
-}
-
-static NSURL* pathToNSURL(const SGPath& aPath)
-{
- return [NSURL fileURLWithPath:stdStringToCocoa(aPath.str())];
-}
-
// 10.6 compiler won't accept block-scoped locals in Objective-C++,
// so making these globals.
static NSString* completion_path = nil;
--- /dev/null
+// CocoaHelpers.h - C++ interface to Cocoa/AppKit helpers
+
+// Copyright (C) 2013 James Turner <zakalawe@mac.com>
+//
+// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+#ifndef FG_GUI_COCOA_HELPERS_H
+#define FG_GUI_COCOA_HELPERS_H
+
+#include <string>
+
+#include <simgear/misc/sg_path.hxx>
+
+/**
+ * open a URL using the system's web-browser
+ */
+void cocoaOpenUrl(const std::string& url);
+
+/**
+ * Cocoa implementation so we can use NSURL
+ */
+SGPath platformDefaultDataPath();
+
+#endif // of FG_GUI_COCOA_HELPERS_H
\ No newline at end of file
--- /dev/null
+// CocoaHelpers.mm - C++ implementation of Cocoa/AppKit helpers
+
+// Copyright (C) 2013 James Turner <zakalawe@mac.com>
+//
+// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+#include "CocoaHelpers.h"
+#include "CocoaHelpers_private.h"
+
+// standard
+#include <string>
+
+// OS
+#include <Cocoa/Cocoa.h>
+#include <Foundation/NSAutoreleasePool.h>
+
+// simgear
+#include <simgear/misc/sg_path.hxx>
+
+// flightgear
+#include <GUI/MessageBox.hxx>
+
+NSString* stdStringToCocoa(const std::string& s)
+{
+ return [NSString stringWithUTF8String:s.c_str()];
+}
+
+std::string stdStringFromCocoa(NSString* s)
+{
+ return std::string([s UTF8String]);
+}
+
+NSURL* pathToNSURL(const SGPath& aPath)
+{
+ return [NSURL fileURLWithPath:stdStringToCocoa(aPath.str())];
+}
+
+SGPath URLToPath(NSURL* url)
+{
+ if (!url) {
+ return SGPath();
+ }
+
+ return SGPath([[url path] UTF8String]);
+}
+
+flightgear::MessageBoxResult cocoaMessageBox(const std::string& msg,
+ const std::string& text)
+{
+ CocoaAutoreleasePool pool;
+ NSAlert* alert = [NSAlert alertWithMessageText:stdStringToCocoa(msg)
+ defaultButton:nil /* localized 'ok' */
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:@"%@",stdStringToCocoa(text)];
+ [[alert retain] autorelease];
+ [alert runModal];
+ return flightgear::MSG_BOX_OK;
+}
+
+
+
+flightgear::MessageBoxResult cocoaFatalMessage(const std::string& msg,
+ const std::string& text)
+{
+ CocoaAutoreleasePool pool;
+ NSAlert* alert = [NSAlert alertWithMessageText:stdStringToCocoa(msg)
+ defaultButton:@"Quit FlightGear"
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:@"%@", stdStringToCocoa(text)];
+ [[alert retain] autorelease];
+ [alert runModal];
+ return flightgear::MSG_BOX_OK;
+}
+
+void cocoaOpenUrl(const std::string& url)
+{
+ CocoaAutoreleasePool pool;
+ NSURL* nsu = [NSURL URLWithString:stdStringToCocoa(url)];
+ [[NSWorkspace sharedWorkspace] openURL:nsu];
+}
+
+CocoaAutoreleasePool::CocoaAutoreleasePool()
+{
+ pool = [[NSAutoreleasePool alloc] init];
+}
+
+CocoaAutoreleasePool::~CocoaAutoreleasePool()
+{
+ [pool release];
+}
+
+SGPath platformDefaultDataPath()
+{
+ CocoaAutoreleasePool ap;
+ NSFileManager* fm = [NSFileManager defaultManager];
+
+ NSURL* appSupportUrl = [fm URLForDirectory:NSApplicationSupportDirectory
+ inDomain:NSUserDomainMask
+ appropriateForURL:Nil
+ create:YES
+ error:nil];
+ if (!appSupportUrl) {
+ return SGPath();
+ }
+
+ SGPath appData(URLToPath(appSupportUrl));
+ appData.append("FlightGear");
+ return appData;
+}
--- /dev/null
+// CocoaHelpers_private.h - common Objective-C/Cocoa helper functions
+
+// Copyright (C) 2013 James Turner <zakalawe@mac.com>
+//
+// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+
+#ifndef FG_GUI_COCOA_HELPERS_PRIVATE_H
+#define FG_GUI_COCOA_HELPERS_PRIVATE_H
+
+#include <string>
+
+// forward decls
+class SGPath;
+
+@class NSString;
+@class NSURL;
+@class NSAutoreleasePool;
+
+NSString* stdStringToCocoa(const std::string& s);
+NSURL* pathToNSURL(const SGPath& aPath);
+SGPath URLToPath(NSURL* url);
+std::string stdStringFromCocoa(NSString* s);
+
+class CocoaAutoreleasePool
+{
+public:
+ CocoaAutoreleasePool();
+
+ ~CocoaAutoreleasePool();
+
+private:
+ NSAutoreleasePool* pool;
+};
+
+#endif
\ No newline at end of file
+++ /dev/null
-
-#include <string>
-
-#include <Cocoa/Cocoa.h>
-#include <GUI/CocoaAutoreleasePool.hxx>
-#include <GUI/MessageBox.hxx>
-
-static NSString* stdStringToCocoa(const std::string& s)
-{
- return [NSString stringWithUTF8String:s.c_str()];
-}
-
-flightgear::MessageBoxResult cocoaMessageBox(const std::string& msg,
- const std::string& text)
-{
- CocoaAutoreleasePool pool;
- NSAlert* alert = [NSAlert alertWithMessageText:stdStringToCocoa(msg)
- defaultButton:nil /* localized 'ok' */
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:@"%@",stdStringToCocoa(text)];
- [[alert retain] autorelease];
- [alert runModal];
- return flightgear::MSG_BOX_OK;
-}
-
-
-
-flightgear::MessageBoxResult cocoaFatalMessage(const std::string& msg,
- const std::string& text)
-{
- CocoaAutoreleasePool pool;
- NSAlert* alert = [NSAlert alertWithMessageText:stdStringToCocoa(msg)
- defaultButton:@"Quit FlightGear"
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:@"%@", stdStringToCocoa(text)];
- [[alert retain] autorelease];
- [alert runModal];
- return flightgear::MSG_BOX_OK;
-}
-
#include <map>
#include <Main/globals.hxx>
-#include <GUI/CocoaAutoreleasePool.hxx>
+#include <GUI/CocoaHelpers_private.h>
class CocoaMouseCursor::CocoaMouseCursorPrivate
{
};
-/**
- * open a URL using the system's web-browser
- */
-void cocoaOpenUrl(const std::string& url);
-
#endif // __MENUBAR_HXX
#include <simgear/misc/strutils.hxx>
#include <Main/fg_props.hxx>
-#include <GUI/CocoaAutoreleasePool.hxx>
+#include <GUI/CocoaHelpers_private.h>
#include <iostream>
@end
-static NSString* stdStringToCocoa(const string& s)
-{
- return [NSString stringWithUTF8String:s.c_str()];
-}
-
static void setFunctionKeyShortcut(const std::string& shortcut, NSMenuItem* item)
{
unichar shortcutChar = NSF1FunctionKey;
// no-op
}
-void cocoaOpenUrl(const std::string& url)
-{
- CocoaAutoreleasePool pool;
- NSURL* nsu = [NSURL URLWithString:stdStringToCocoa(url)];
- [[NSWorkspace sharedWorkspace] openURL:nsu];
-}
# include <shellapi.h>
#endif
-#ifdef SG_MAC
-# include "FGCocoaMenuBar.hxx" // for cocoaOpenUrl
+#if defined(SG_MAC)
+# include <GUI/CocoaHelpers.h> // for cocoaOpenUrl
#endif
#include "gui.h"
#include "positioninit.hxx"
#include "util.hxx"
+#if defined(SG_MAC)
+#include <GUI/CocoaHelpers.h> // for Mac impl of platformDefaultDataPath()
+#endif
+
using std::string;
using std::endl;
using std::cerr;
return config;
}
-#elif __APPLE__
-#include <CoreServices/CoreServices.h>
-
-static SGPath platformDefaultDataPath()
-{
- FSRef ref;
- OSErr err = FSFindFolder(kUserDomain, kApplicationSupportFolderType, false, &ref);
- if (err) {
- return SGPath();
- }
+#elif defined(SG_MAC)
- unsigned char path[1024];
- if (FSRefMakePath(&ref, path, 1024) != noErr) {
- return SGPath();
- }
+// platformDefaultDataPath defined in GUI/CocoaHelpers.h
- SGPath appData;
- appData.set((const char*) path);
- appData.append("FlightGear");
- return appData;
-}
#else
static SGPath platformDefaultDataPath()
{
#include <Cocoa/Cocoa.h>
-namespace {
- class CocoaAutoreleasePool
- {
- public:
- CocoaAutoreleasePool()
- {
- pool = [[NSAutoreleasePool alloc] init];
- }
-
- ~CocoaAutoreleasePool()
- {
- [pool release];
- }
-
- private:
- NSAutoreleasePool* pool;
- };
-}
-
-static NSString* stdStringToCocoa(const std::string& s)
-{
- return [NSString stringWithUTF8String:s.c_str()];
-}
-
-static std::string stdStringFromCocoa(NSString* s)
-{
- return std::string([s UTF8String]);
-}
+#include <GUI/CocoaHelpers_private.h>
/**
*/