ToDo: long outstanding patch to allow access to system paths in background mode

Thanks Damien Plisson for contributing the Carbon and Cocoa implementation
This commit is contained in:
Andrea Weikert
2011-01-05 14:00:14 +00:00
parent 8e29c7b76f
commit 195cc9c6a6
29 changed files with 990 additions and 285 deletions

View File

@@ -36,10 +36,12 @@ set(SRC
intern/GHOST_Buttons.cpp
intern/GHOST_CallbackEventConsumer.cpp
intern/GHOST_C-api.cpp
intern/GHOST_Path-api.cpp
intern/GHOST_DisplayManager.cpp
intern/GHOST_EventManager.cpp
intern/GHOST_EventPrinter.cpp
intern/GHOST_ISystem.cpp
intern/GHOST_ISystemPaths.cpp
intern/GHOST_ModifierKeys.cpp
intern/GHOST_NDOFManager.cpp
intern/GHOST_Path-api.cpp
@@ -87,20 +89,24 @@ if(APPLE)
list(APPEND SRC
intern/GHOST_DisplayManagerCocoa.mm
intern/GHOST_SystemCocoa.mm
intern/GHOST_SystemPathsCocoa.mm
intern/GHOST_WindowCocoa.mm
intern/GHOST_DisplayManagerCocoa.h
intern/GHOST_SystemCocoa.h
intern/GHOST_SystemPathsCocoa.h
intern/GHOST_WindowCocoa.h
)
else()
list(APPEND SRC
intern/GHOST_DisplayManagerCarbon.cpp
intern/GHOST_SystemCarbon.cpp
intern/GHOST_SystemPathsCarbon.cpp
intern/GHOST_WindowCarbon.cpp
intern/GHOST_DisplayManagerCarbon.h
intern/GHOST_SystemCarbon.h
intern/GHOST_SystemPathsCarbon.h
intern/GHOST_WindowCarbon.h
)
endif()
@@ -115,10 +121,12 @@ elseif(UNIX)
list(APPEND SRC
intern/GHOST_DisplayManagerX11.cpp
intern/GHOST_SystemX11.cpp
intern/GHOST_SystemPathsX11.cpp
intern/GHOST_WindowX11.cpp
intern/GHOST_DisplayManagerX11.h
intern/GHOST_SystemX11.h
intern/GHOST_SystemPathsX11.h
intern/GHOST_WindowX11.h
)
@@ -134,12 +142,14 @@ elseif(WIN32)
list(APPEND SRC
intern/GHOST_DisplayManagerWin32.cpp
intern/GHOST_SystemWin32.cpp
intern/GHOST_SystemPathsWin32.cpp
intern/GHOST_WindowWin32.cpp
intern/GHOST_DropTargetWin32.cpp
intern/GHOST_DisplayManagerWin32.h
intern/GHOST_DropTargetWin32.h
intern/GHOST_SystemWin32.h
intern/GHOST_SystemPathsWin32.h
intern/GHOST_WindowWin32.h
)
endif()

View File

@@ -46,7 +46,6 @@ extern "C" {
* In the API the pointer is casted to the actual C++ class.
* @param name Name of the handle to create.
*/
#define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
GHOST_DECLARE_HANDLE(GHOST_SystemHandle);
GHOST_DECLARE_HANDLE(GHOST_TimerTaskHandle);

View File

@@ -370,25 +370,7 @@ public:
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const = 0;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const = 0;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const = 0;
protected:
/**
* Initialize the system.

View File

@@ -0,0 +1,93 @@
/**
* $Id: $
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef _GHOST_ISYSTEMPATHS_H_
#define _GHOST_ISYSTEMPATHS_H_
#include "GHOST_Types.h"
class GHOST_ISystemPaths
{
public:
/**
* Creates the one and only system.
* @return An indication of success.
*/
static GHOST_TSuccess create();
/**
* Disposes the one and only system.
* @return An indication of success.
*/
static GHOST_TSuccess dispose();
/**
* Returns a pointer to the one and only system (nil if it hasn't been created).
* @return A pointer to the system.
*/
static GHOST_ISystemPaths* get();
protected:
/**
* Constructor.
* Protected default constructor to force use of static createSystem member.
*/
GHOST_ISystemPaths() {}
/**
* Destructor.
* Protected default constructor to force use of static dispose member.
*/
virtual ~GHOST_ISystemPaths() {}
public:
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const = 0;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const = 0;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const = 0;
private:
/** The one and only system paths*/
static GHOST_ISystemPaths* m_systemPaths;
};
#endif

View File

@@ -36,6 +36,20 @@
extern "C" {
#endif
GHOST_DECLARE_HANDLE(GHOST_SystemPathsHandle);
/**
* Creates the one and only instance of the system path access.
* @return An indication of success.
*/
extern GHOST_TSuccess GHOST_CreateSystemPaths(void);
/**
* Disposes the one and only system.
* @return An indication of success.
*/
extern GHOST_TSuccess GHOST_DisposeSystemPaths(void);
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.

View File

@@ -33,6 +33,8 @@
#include "MEM_guardedalloc.h"
#endif
#define GHOST_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
typedef char GHOST_TInt8;
typedef unsigned char GHOST_TUns8;
typedef short GHOST_TInt16;

View File

@@ -11,7 +11,7 @@ if window_system == 'darwin':
sources += env.Glob('intern/*.mm')
pf = ['GHOST_DisplayManager', 'GHOST_System', 'GHOST_Window', 'GHOST_DropTarget']
pf = ['GHOST_DisplayManager', 'GHOST_System', 'GHOST_SystemPaths', 'GHOST_Window', 'GHOST_DropTarget']
defs=['_USE_MATH_DEFINES']
if window_system in ('linux2', 'openbsd3', 'sunos5', 'freebsd7', 'freebsd8', 'freebsd9', 'irix6', 'aix4', 'aix5'):

View File

@@ -0,0 +1,104 @@
/**
* $Id: GHOST_ISystem.cpp 28254 2010-04-18 10:28:37Z campbellbarton $
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/**
* $Id: GHOST_ISystem.cpp 28254 2010-04-18 10:28:37Z campbellbarton $
* Copyright (C) 2001 NaN Technologies B.V.
* @author Maarten Gribnau
* @date May 7, 2001
*/
#include "GHOST_ISystemPaths.h"
#ifdef WIN32
# include "GHOST_SystemPathsWin32.h"
#else
# ifdef __APPLE__
# ifdef GHOST_COCOA
# include "GHOST_SystemPathsCocoa.h"
# else
# include "GHOST_SystemPathsCarbon.h"
# endif
# else
# include "GHOST_SystemPathsX11.h"
# endif
#endif
GHOST_ISystemPaths* GHOST_ISystemPaths::m_systemPaths = 0;
GHOST_TSuccess GHOST_ISystemPaths::create()
{
GHOST_TSuccess success;
if (!m_systemPaths) {
#ifdef WIN32
m_systemPaths = new GHOST_SystemPathsWin32 ();
#else
# ifdef __APPLE__
# ifdef GHOST_COCOA
m_systemPaths = new GHOST_SystemPathsCocoa ();
# else
m_systemPaths = new GHOST_SystemPathsarbon ();
# endif
# else
m_systemPaths = new GHOST_SystemPathsX11 ();
# endif
#endif
success = m_systemPaths != 0 ? GHOST_kSuccess : GHOST_kFailure;
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_TSuccess GHOST_ISystemPaths::dispose()
{
GHOST_TSuccess success = GHOST_kSuccess;
if (m_systemPaths) {
delete m_systemPaths;
m_systemPaths = 0;
}
else {
success = GHOST_kFailure;
}
return success;
}
GHOST_ISystemPaths* GHOST_ISystemPaths::get()
{
if (!m_systemPaths) {
create();
}
return m_systemPaths;
}

View File

@@ -28,23 +28,34 @@
*/
#include "intern/GHOST_Debug.h"
#include "GHOST_Types.h"
#include "GHOST_Path-api.h"
#include "GHOST_ISystem.h"
#include "GHOST_ISystemPaths.h"
GHOST_TSuccess GHOST_CreateSystemPaths(void)
{
return GHOST_ISystemPaths::create();;
}
GHOST_TSuccess GHOST_DisposeSystemPaths(void)
{
return GHOST_ISystemPaths::dispose();
}
const GHOST_TUns8* GHOST_getSystemDir()
{
GHOST_ISystem* system = GHOST_ISystem::getSystem();
return system ? system->getSystemDir() : NULL;
GHOST_ISystemPaths* systemPaths = GHOST_ISystemPaths::get();
return systemPaths ? systemPaths->getSystemDir() : 0;
}
const GHOST_TUns8* GHOST_getUserDir()
{
GHOST_ISystem* system = GHOST_ISystem::getSystem();
return system ? system->getUserDir() : NULL; /* will be NULL in background mode */
GHOST_ISystemPaths* systemPaths = GHOST_ISystemPaths::get();
return systemPaths ? systemPaths->getUserDir() : 0; /* shouldn't be NULL */
}
const GHOST_TUns8* GHOST_getBinaryDir()
{
GHOST_ISystem* system = GHOST_ISystem::getSystem();
return system ? system->getBinaryDir() : NULL; /* will be NULL in background mode */
GHOST_ISystemPaths* systemPaths = GHOST_ISystemPaths::get();
return systemPaths ? systemPaths->getBinaryDir() : 0; /* shouldn't be NULL */
}

View File

@@ -297,25 +297,7 @@ public:
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const = 0;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const = 0;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const = 0;
protected:
/**
* Initialize the system.

View File

@@ -1214,39 +1214,3 @@ void GHOST_SystemCarbon::putClipboard(GHOST_TInt8 *buffer, bool selection) const
CFRelease(textData);
}
}
const GHOST_TUns8* GHOST_SystemCarbon::getSystemDir() const
{
return (GHOST_TUns8*)"/Library/Application Support";
}
const GHOST_TUns8* GHOST_SystemCarbon::getUserDir() const
{
static char usrPath[256] = "";
char* env = getenv("HOME");
if (env) {
strncpy(usrPath, env, 245);
usrPath[245]=0;
strcat(usrPath, "/Library/Application Support");
return (GHOST_TUns8*) usrPath;
}
else
return NULL;
}
const GHOST_TUns8* GHOST_SystemCarbon::getBinaryDir() const
{
CFURLRef bundleURL;
CFStringRef pathStr;
static char path[256];
CFBundleRef mainBundle = CFBundleGetMainBundle();
bundleURL = CFBundleCopyBundleURL(mainBundle);
pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
CFStringGetCString(pathStr, path, 255, kCFStringEncodingASCII);
CFRelease(pathStr);
CFRelease(bundleURL);
return (GHOST_TUns8*)path;
}

View File

@@ -190,27 +190,6 @@ public:
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const;
protected:
/**
* Initializes the system.

View File

@@ -213,26 +213,6 @@ public:
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const;
/**
* Handles a window event. Called by GHOST_WindowCocoa window delegate
* @param eventType The type of window event

View File

@@ -1796,67 +1796,3 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
[pool drain];
}
#pragma mark Base directories retrieval
const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSLocalDomainMask, YES);
if ([paths count] > 0)
basePath = [paths objectAtIndex:0];
else {
[pool drain];
return NULL;
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}
const GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([paths count] > 0)
basePath = [paths objectAtIndex:0];
else {
[pool drain];
return NULL;
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}
const GHOST_TUns8* GHOST_SystemCocoa::getBinaryDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *basePath;
basePath = [[NSBundle mainBundle] bundlePath];
if (basePath == nil) {
[pool drain];
return NULL;
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}

View File

@@ -0,0 +1,74 @@
/**
* $Id: $
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef _GHOST_SYSTEMPATHS_H_
#define _GHOST_SYSTEMPATHS_H_
#include "GHOST_ISystemPaths.h"
class GHOST_SystemPaths : public GHOST_ISystemPaths
{
protected:
/**
* Constructor.
* Protected default constructor to force use of static createSystem member.
*/
GHOST_SystemPaths(){};
/**
* Destructor.
* Protected default constructor to force use of static dispose member.
*/
virtual ~GHOST_SystemPaths(){};
public:
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const = 0;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const = 0;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const = 0;
};
#endif

View File

@@ -0,0 +1,78 @@
/**
* $Id: $
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Damien Plisson 2010
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <Carbon/Carbon.h>
#include <ApplicationServices/ApplicationServices.h>
#include "GHOST_SystemPathsCarbon.h"
/***/
GHOST_SystemPathsCarbon::GHOST_SystemPathsCarbon()
{
}
GHOST_SystemPathsCarbon::~GHOST_SystemPathsCarbon()
{
}
const GHOST_TUns8* GHOST_SystemPathsCarbon::getSystemDir() const
{
return (GHOST_TUns8*)"/Library/Application Support";
}
const GHOST_TUns8* GHOST_SystemPathsCarbon::getUserDir() const
{
static char usrPath[256] = "";
char* env = getenv("HOME");
if (env) {
strncpy(usrPath, env, 245);
usrPath[245]=0;
strcat(usrPath, "/Library/Application Support");
return (GHOST_TUns8*) usrPath;
}
else
return NULL;
}
const GHOST_TUns8* GHOST_SystemPathsCarbon::getBinaryDir() const
{
CFURLRef bundleURL;
CFStringRef pathStr;
static char path[256];
CFBundleRef mainBundle = CFBundleGetMainBundle();
bundleURL = CFBundleCopyBundleURL(mainBundle);
pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
CFStringGetCString(pathStr, path, 255, kCFStringEncodingASCII);
CFRelease(pathStr);
CFRelease(bundleURL);
return (GHOST_TUns8*)path;
}

View File

@@ -0,0 +1,83 @@
/**
* $Id: $
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2010 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Damien Plisson 2010
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef _GHOST_SYSTEM_PATHS_CARBON_H_
#define _GHOST_SYSTEM_PATHS_CARBON_H_
#ifndef __APPLE__
#error Apple OSX only!
#endif // __APPLE__
#include <Carbon/Carbon.h>
#include "GHOST_SystemPaths.h"
/**
* OSX/Carbon Implementation of GHOST_SystemPaths class.
* @see GHOST_System.
* @author Andrea Weikert
* @date Aug 1, 2010
*/
class GHOST_SystemPathsCarbon : public GHOST_SystemPaths {
public:
/**
* Constructor.
*/
GHOST_SystemPathsCarbon();
/**
* Destructor.
*/
~GHOST_SystemPathsCarbon();
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const;
};
#endif // _GHOST_SYSTEM_CARBON_H_

View File

@@ -0,0 +1,75 @@
/**
* $Id: $
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2010 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Damien Plisson 2010
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef _GHOST_SYSTEM_PATHS_COCOA_H_
#define _GHOST_SYSTEM_PATHS_COCOA_H_
#ifndef __APPLE__
#error Apple OSX only!
#endif // __APPLE__
#include "GHOST_SystemPaths.h"
class GHOST_SystemPathsCocoa : public GHOST_SystemPaths {
public:
/**
* Constructor.
*/
GHOST_SystemPathsCocoa();
/**
* Destructor.
*/
~GHOST_SystemPathsCocoa();
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
virtual const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
virtual const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const;
};
#endif // _GHOST_SYSTEM_COCOA_H_

View File

@@ -0,0 +1,116 @@
/**
* $Id: $
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2010 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Damien Plisson 2010
*
* ***** END GPL LICENSE BLOCK *****
*/
#import <Cocoa/Cocoa.h>
/*For the currently not ported to Cocoa keyboard layout functions (64bit & 10.6 compatible)*/
#include <Carbon/Carbon.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include "GHOST_SystemPathsCocoa.h"
#pragma mark initialization/finalization
GHOST_SystemPathsCocoa::GHOST_SystemPathsCocoa()
{
}
GHOST_SystemPathsCocoa::~GHOST_SystemPathsCocoa()
{
}
#pragma mark Base directories retrieval
const GHOST_TUns8* GHOST_SystemPathsCocoa::getSystemDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSLocalDomainMask, YES);
if ([paths count] > 0)
basePath = [paths objectAtIndex:0];
else {
[pool drain];
return NULL;
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}
const GHOST_TUns8* GHOST_SystemPathsCocoa::getUserDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *basePath;
NSArray *paths;
paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
if ([paths count] > 0)
basePath = [paths objectAtIndex:0];
else {
[pool drain];
return NULL;
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}
const GHOST_TUns8* GHOST_SystemPathsCocoa::getBinaryDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *basePath;
basePath = [[NSBundle mainBundle] bundlePath];
if (basePath == nil) {
[pool drain];
return NULL;
}
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
[pool drain];
return tempPath;
}

View File

@@ -0,0 +1,81 @@
/**
* $Id: GHOST_SystemWin32.cpp 30060 2010-07-06 20:31:55Z elubie $
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2011 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Blender Foundation
* Andrea Weikert
*
* ***** END GPL LICENSE BLOCK *****
*/
#include "GHOST_SystemPathsWin32.h"
#define WIN32_LEAN_AND_MEAN
#ifdef _WIN32_IE
#undef _WIN32_IE
#endif
#define _WIN32_IE 0x0501
#include <windows.h>
#include <shlobj.h>
GHOST_SystemPathsWin32::GHOST_SystemPathsWin32()
{
}
GHOST_SystemPathsWin32::~GHOST_SystemPathsWin32()
{
}
const GHOST_TUns8* GHOST_SystemPathsWin32::getSystemDir() const
{
static char knownpath[MAX_PATH];
HRESULT hResult = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath);
if (hResult == S_OK)
{
return (GHOST_TUns8*)knownpath;
}
return NULL;
}
const GHOST_TUns8* GHOST_SystemPathsWin32::getUserDir() const
{
static char knownpath[MAX_PATH];
HRESULT hResult = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath);
if (hResult == S_OK)
{
return (GHOST_TUns8*)knownpath;
}
return NULL;
}
const GHOST_TUns8* GHOST_SystemPathsWin32::getBinaryDir() const
{
static char fullname[MAX_PATH];
if(GetModuleFileName(0, fullname, MAX_PATH)) {
return (GHOST_TUns8*)fullname;
}
return NULL;
}

View File

@@ -0,0 +1,82 @@
/**
* $Id: $
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef _GHOST_SYSTEM_PATHS_WIN32_H_
#define _GHOST_SYSTEM_PATHS_WIN32_H_
#ifndef WIN32
#error WIN32 only!
#endif // WIN32
#include <windows.h>
#include "GHOST_SystemPaths.h"
/**
* WIN32 Implementation of GHOST_SystemPaths class.
* @see GHOST_SystemPaths.
* @author Andrea Weikert
* @date August 1, 2010
*/
class GHOST_SystemPathsWin32 : public GHOST_SystemPaths {
public:
/**
* Constructor.
*/
GHOST_SystemPathsWin32();
/**
* Destructor.
*/
virtual ~GHOST_SystemPathsWin32();
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/).
*/
const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/).
*/
const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
const GHOST_TUns8* getBinaryDir() const;
};
#endif // _GHOST_SYSTEM_PATHS_WIN32_H_

View File

@@ -0,0 +1,76 @@
/**
* $Id: $
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2010 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
#include "GHOST_SystemPathsX11.h"
#include "GHOST_Debug.h"
// For timing
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h> // for fprintf only
#include <cstdlib> // for exit
#ifndef PREFIX
# define PREFIX "/usr/local"
#endif
using namespace std;
GHOST_SystemPathsX11::GHOST_SystemPathsX11()
{
}
GHOST_SystemPathsX11::~GHOST_SystemPathsX11()
{
}
const GHOST_TUns8* GHOST_SystemPathsX11::getSystemDir() const
{
return (GHOST_TUns8*) PREFIX "/share";
}
const GHOST_TUns8* GHOST_SystemPathsX11::getUserDir() const
{
char* env = getenv("HOME");
if(env) {
return (GHOST_TUns8*) env;
} else {
return NULL;
}
}
const GHOST_TUns8* GHOST_SystemPathsX11::getBinaryDir() const
{
return NULL;
}

View File

@@ -0,0 +1,73 @@
/**
* $Id: $
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2010 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef _GHOST_SYSTEM_PATHS_X11_H_
#define _GHOST_SYSTEM_PATHS_X11_H_
#include "GHOST_SystemPaths.h"
#include "../GHOST_Types.h"
class GHOST_SystemPathsX11 : public GHOST_SystemPaths {
public:
/**
* Constructor
* this class should only be instanciated by GHOST_ISystem.
*/
GHOST_SystemPathsX11();
/**
* Destructor.
*/
virtual ~GHOST_SystemPathsX11();
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
const GHOST_TUns8* getBinaryDir() const;
};
#endif

View File

@@ -851,7 +851,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
* specifies a character code generated by a dead key. A dead key is a key that
* generates a character, such as the umlaut (double-dot), that is combined with
* another character to form a composite character. For example, the umlaut-O
* character (Ö) is generated by typing the dead key for the umlaut character, and
* character (<EFBFBD>) is generated by typing the dead key for the umlaut character, and
* then typing the O key.
*/
case WM_SYSDEADCHAR:
@@ -1209,39 +1209,3 @@ void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const
return;
}
}
const GHOST_TUns8* GHOST_SystemWin32::getSystemDir() const
{
static char knownpath[MAX_PATH];
HRESULT hResult = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath);
if (hResult == S_OK)
{
return (GHOST_TUns8*)knownpath;
}
return NULL;
}
const GHOST_TUns8* GHOST_SystemWin32::getUserDir() const
{
static char knownpath[MAX_PATH];
HRESULT hResult = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath);
if (hResult == S_OK)
{
return (GHOST_TUns8*)knownpath;
}
return NULL;
}
const GHOST_TUns8* GHOST_SystemWin32::getBinaryDir() const
{
static char fullname[MAX_PATH];
if(GetModuleFileName(0, fullname, MAX_PATH)) {
return (GHOST_TUns8*)fullname;
}
return NULL;
}

View File

@@ -187,26 +187,6 @@ public:
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/).
*/
virtual const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/).
*/
virtual const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
virtual const GHOST_TUns8* getBinaryDir() const;
/**
* Creates a drag'n'drop event and pushes it immediately onto the event queue.
* Called by GHOST_DropTargetWin32 class.

View File

@@ -1476,23 +1476,4 @@ void GHOST_SystemX11::putClipboard(GHOST_TInt8 *buffer, bool selection) const
}
}
const GHOST_TUns8* GHOST_SystemX11::getSystemDir() const
{
return (GHOST_TUns8*) PREFIX "/share";
}
const GHOST_TUns8* GHOST_SystemX11::getUserDir() const
{
char* env = getenv("HOME");
if(env) {
return (GHOST_TUns8*) env;
} else {
return NULL;
}
}
const GHOST_TUns8* GHOST_SystemX11::getBinaryDir() const
{
return NULL;
}

View File

@@ -226,26 +226,6 @@ public:
*/
void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
/**
* Determine the base dir in which shared resources are located. It will first try to use
* "unpack and run" path, then look for properly installed path, not including versioning.
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
*/
const GHOST_TUns8* getSystemDir() const;
/**
* Determine the base dir in which user configuration is stored, not including versioning.
* If needed, it will create the base directory.
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
*/
const GHOST_TUns8* getUserDir() const;
/**
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
const GHOST_TUns8* getBinaryDir() const;
/**
* Atom used for ICCCM, WM-spec and Motif.
* We only need get this atom at the start, it's relative

View File

@@ -35,7 +35,7 @@ DIR = $(OCGDIR)/intern/$(LIBNAME)
CCSRCS = GHOST_Buttons.cpp GHOST_System.cpp GHOST_Window.cpp
CCSRCS += GHOST_EventManager.cpp GHOST_EventPrinter.cpp GHOST_WindowManager.cpp
CCSRCS += GHOST_ISystem.cpp GHOST_ModifierKeys.cpp GHOST_TimerManager.cpp
CCSRCS += GHOST_ISystem.cpp GHOST_ISystemPaths.cpp GHOST_ModifierKeys.cpp GHOST_TimerManager.cpp
CCSRCS += GHOST_Rect.cpp GHOST_DisplayManager.cpp GHOST_C-api.cpp
CCSRCS += GHOST_CallbackEventConsumer.cpp
CCSRCS += GHOST_NDOFManager.cpp GHOST_Path-api.cpp

View File

@@ -68,6 +68,7 @@
#ifdef WITH_GAMEENGINE
#include "SYS_System.h"
#endif
#include "GHOST_Path-api.h"
#include "RNA_define.h"
@@ -118,6 +119,8 @@ void WM_init(bContext *C, int argc, char **argv)
wm_ghost_init(C); /* note: it assigns C to ghost! */
wm_init_cursor_data();
}
GHOST_CreateSystemPaths();
wm_operatortype_init();
set_free_windowmanager_cb(wm_close_and_free); /* library.c */
@@ -443,6 +446,9 @@ void WM_exit(bContext *C)
#ifdef WITH_GAMEENGINE
SYS_DeleteSystem(SYS_GetSystem());
#endif
GHOST_DisposeSystemPaths();
if(MEM_get_memory_blocks_in_use()!=0) {
printf("Error Totblock: %d\n", MEM_get_memory_blocks_in_use());
MEM_printmemlist();