As-yet uncommitted changes from end of summer. General code cleanup Mac-side, removed some unnecessary NSAutoreleasePool guards, etc. By no means complete -- just wanted to get this in and do a fresh checkout on another machine.

This commit is contained in:
Mike Erwin 2010-12-14 22:43:52 +00:00
parent 4bfd915f9c
commit a7f2cbc88f
6 changed files with 503 additions and 618 deletions

@ -27,7 +27,7 @@
*/
/**
* @file GHOST_ISystem.h
* Main interface file for C++ Api with declaration of GHOST_ISystem interface
* Main interface file for C++ API with declaration of GHOST_ISystem interface
* class.
* Contains the doxygen documentation main page.
*/

@ -29,7 +29,6 @@
#include "GHOST_Buttons.h"
GHOST_Buttons::GHOST_Buttons()
{
clear();
@ -39,37 +38,37 @@ GHOST_Buttons::~GHOST_Buttons() {}
bool GHOST_Buttons::get(GHOST_TButtonMask mask) const
{
switch (mask) {
case GHOST_kButtonMaskLeft:
return m_ButtonLeft;
case GHOST_kButtonMaskMiddle:
return m_ButtonMiddle;
case GHOST_kButtonMaskRight:
return m_ButtonRight;
default:
return false;
}
switch (mask) {
case GHOST_kButtonMaskLeft:
return m_ButtonLeft;
case GHOST_kButtonMaskMiddle:
return m_ButtonMiddle;
case GHOST_kButtonMaskRight:
return m_ButtonRight;
default:
return false;
}
}
void GHOST_Buttons::set(GHOST_TButtonMask mask, bool down)
{
switch (mask) {
case GHOST_kButtonMaskLeft:
m_ButtonLeft = down; break;
case GHOST_kButtonMaskMiddle:
m_ButtonMiddle = down; break;
case GHOST_kButtonMaskRight:
m_ButtonRight = down; break;
default:
break;
}
switch (mask) {
case GHOST_kButtonMaskLeft:
m_ButtonLeft = down; break;
case GHOST_kButtonMaskMiddle:
m_ButtonMiddle = down; break;
case GHOST_kButtonMaskRight:
m_ButtonRight = down; break;
default:
break;
}
}
void GHOST_Buttons::clear()
{
m_ButtonLeft = false;
m_ButtonMiddle = false;
m_ButtonRight = false;
m_ButtonLeft = false;
m_ButtonMiddle = false;
m_ButtonRight = false;
}
bool GHOST_Buttons::anyDown() const

@ -21,13 +21,14 @@
*
* The Original Code is: all of this file.
*
* Contributor(s): Maarten Gribnau 05/2001
* Damien Plisson 09/2009
* Contributor(s): Maarten Gribnau 05/2001
* Damien Plisson 09/2009
*
* ***** END GPL LICENSE BLOCK *****
*/
/**
* @file GHOST_SystemCocoa.h
* @file GHOST_SystemCocoa.h
* Declaration of GHOST_SystemCocoa class.
*/
@ -44,20 +45,20 @@ class GHOST_EventCursor;
class GHOST_EventKey;
class GHOST_EventWindow;
class GHOST_WindowCocoa;
class NSAutoreleasePool; // actually Obj-C, but GHOST_ISystem.cpp doesn't understand @class syntax
class GHOST_SystemCocoa : public GHOST_System {
public:
/**
* Constructor.
*/
GHOST_SystemCocoa();
/**
* Destructor.
*/
~GHOST_SystemCocoa();
/**
* Constructor.
*/
GHOST_SystemCocoa();
/**
* Destructor.
*/
~GHOST_SystemCocoa();
/***************************************************************************************
** Time(r) functionality
***************************************************************************************/
@ -68,7 +69,7 @@ public:
* Based on ANSI clock() routine.
* @return The number of milliseconds.
*/
virtual GHOST_TUns64 getMilliSeconds() const;
GHOST_TUns64 getMilliSeconds() const;
/***************************************************************************************
** Display/window management functionality
@ -78,31 +79,30 @@ public:
* Returns the number of displays on this system.
* @return The number of displays.
*/
virtual GHOST_TUns8 getNumDisplays() const;
GHOST_TUns8 getNumDisplays() const;
/**
* Returns the dimensions of the main display on this system.
* @return The dimension of the main display.
*/
virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const;
void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const;
/**
* Create a new window.
* The new window is added to the list of windows managed.
* The new window is added to the list of windows managed.
* Never explicitly delete the window, use disposeWindow() instead.
* @param title The name of the window (displayed in the title bar of the window if the OS supports it).
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state of the window when opened.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
* @param parentWindow Parent (embedder) window
* @return The new window (or 0 if creation failed).
* @param title The name of the window (displayed in the title bar of the window if the OS supports it).
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state of the window when opened.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
* @param parentWindow Parent (embedder) window
* @return The new window (or 0 if creation failed).
*/
virtual GHOST_IWindow* createWindow(
GHOST_IWindow* createWindow(
const STR_String& title,
GHOST_TInt32 left,
GHOST_TInt32 top,
@ -114,166 +114,166 @@ public:
const GHOST_TUns16 numOfAASamples = 0,
const GHOST_TEmbedderWindowID parentWindow = 0
);
virtual GHOST_TSuccess beginFullScreen(
GHOST_TSuccess beginFullScreen(
const GHOST_DisplaySetting& setting,
GHOST_IWindow** window,
const bool stereoVisual
);
virtual GHOST_TSuccess endFullScreen( void );
GHOST_TSuccess endFullScreen( void );
/***************************************************************************************
** Event management functionality
***************************************************************************************/
/**
* Gets events from the system and stores them in the queue.
* @param waitForEvent Flag to wait for an event (or return immediately).
* @return Indication of the presence of events.
* @param waitForEvent Flag to wait for an event (or return immediately).
* @return Indication of the presence of events.
*/
virtual bool processEvents(bool waitForEvent);
bool processEvents(bool waitForEvent);
/**
* Handle User request to quit, from Menu bar Quit, and Cmd+Q
* Display alert panel if changes performed since last save
*/
GHOST_TUns8 handleQuitRequest();
/**
* Handle Cocoa openFile event
* Display confirmation request panel if changes performed since last save
*/
bool handleOpenDocumentRequest(void *filepathStr);
bool handleOpenDocumentRequest(void *filepathStr);
/**
* Handles a drag'n'drop destination event. Called by GHOST_WindowCocoa window subclass
* @param eventType The type of drag'n'drop event
* @param draggedObjectType The type object concerned (currently array of file names, string, TIFF image)
* @param mouseX x mouse coordinate (in cocoa base window coordinates)
* @param mouseY y mouse coordinate
* @param window The window on which the event occurred
* @return Indication whether the event was handled.
*/
* Handles a drag'n'drop destination event. Called by GHOST_WindowCocoa window subclass
* @param eventType The type of drag'n'drop event
* @param draggedObjectType The type object concerned (currently array of file names, string, TIFF image)
* @param mouseX x mouse coordinate (in cocoa base window coordinates)
* @param mouseY y mouse coordinate
* @param window The window on which the event occurred
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleDraggingEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType,
GHOST_WindowCocoa* window, int mouseX, int mouseY, void* data);
GHOST_WindowCocoa* window, int mouseX, int mouseY, void* data);
/***************************************************************************************
** Cursor management functionality
***************************************************************************************/
/**
* Returns the current location of the cursor (location in screen coordinates)
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const;
GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const;
/**
* Updates the location of the cursor (location in screen coordinates).
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y);
GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y);
/***************************************************************************************
** Access to mouse button and keyboard states.
***************************************************************************************/
/**
* Returns the state of all modifier keys.
* @param keys The state of all modifier keys (true == pressed).
* @return Indication of success.
* @param keys The state of all modifier keys (true == pressed).
* @return Indication of success.
*/
virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const;
GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const;
/**
* Returns the state of the mouse buttons (ouside the message queue).
* @param buttons The state of the buttons.
* @return Indication of success.
* @param buttons The state of the buttons.
* @return Indication of success.
*/
virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
/**
* Returns Clipboard data
* @param selection Indicate which buffer to return
* @return Returns the selected buffer
* @param selection Indicate which buffer to return
* @return Returns the selected buffer
*/
virtual GHOST_TUns8* getClipboard(bool selection) const;
GHOST_TUns8* getClipboard(bool selection) const;
/**
* Puts buffer to system clipboard
* @param buffer The buffer to be copied
* @param selection Indicates which buffer to copy too, only used on X11
* @param buffer The buffer to be copied
* @param selection Indicates which buffer to copy too, only used on X11
*/
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
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;
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;
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;
* Determine the directory of the current binary
* @return Unsigned char string pointing to the binary dir
*/
const GHOST_TUns8* getBinaryDir() const;
/**
* Handles a window event. Called by GHOST_WindowCocoa window delegate
* @param eventType The type of window event
* @param window The window on which the event occurred
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window);
* Handles a window event. Called by GHOST_WindowCocoa window delegate
* @param eventType The type of window event
* @param window The window on which the event occurred
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window);
/**
* Handles the Cocoa event telling the application has become active (again)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleApplicationBecomeActiveEvent();
* Handles the Cocoa event telling the application has become active (again)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleApplicationBecomeActiveEvent();
/**
* External objects should call this when they send an event outside processEvents.
*/
* External objects should call this when they send an event outside processEvents.
*/
void notifyExternalEventProcessed();
protected:
/**
* Initializes the system.
* For now, it justs registers the window class (WNDCLASS).
* @return A success value.
* @return A success value.
*/
virtual GHOST_TSuccess init();
GHOST_TSuccess init();
/**
* Handles a tablet pen event.
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleTabletEvent(void *eventPtr);
/**
* Helps handleTabletEvent function.
*/
/**
* Handles a tablet pen event.
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleTabletEvent(void *eventPtr);
/**
* Helps handleTabletEvent function.
*/
void fillTabletData(GHOST_TabletData& tablet, void* event_ptr);
/**
* Handles a tablet proximity event. Sets pen or mouse ID for later events.
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
* @return Indication whether the event was handled.
*/
* Handles a tablet proximity event. Sets pen or mouse ID for later events.
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleTabletProximity(void *eventPtr);
/** Tablet Mouse and Pen IDs, used to correlate events with the tool that caused them. */
@ -286,24 +286,24 @@ protected:
GHOST_TTabletMode m_tablet_pen_mode;
/**
* Handles a mouse event.
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleMouseEvent(void *eventPtr);
* Handles a mouse event.
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleMouseEvent(void *eventPtr);
/**
* Handles a key event.
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleKeyEvent(void *eventPtr);
/**
* Handles a key event.
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
* @return Indication whether the event was handled.
*/
GHOST_TSuccess handleKeyEvent(void *eventPtr);
/**
* Performs the actual cursor position update (location in screen coordinates).
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
* @param x The x-coordinate of the cursor.
* @param y The y-coordinate of the cursor.
* @return Indication of success.
*/
GHOST_TSuccess setMouseCursorPosition(float x, float y);
@ -313,29 +313,31 @@ protected:
/** Event has been processed directly by Cocoa (or NDOF manager) and has sent a ghost event to be dispatched */
bool m_outsideLoopEventProcessed;
/** Raised window is not yet known by the window manager, so delay application become active event handling */
bool m_needDelayedApplicationBecomeActiveEventProcessing;
/** Mouse buttons state */
GHOST_TUns32 m_pressedMouseButtons;
/** State of the modifiers. */
GHOST_TUns32 m_modifierMask;
/** Ignores window size messages (when window is dragged). */
bool m_ignoreWindowSizedMessages;
/** State of the modifiers. */
GHOST_TUns32 m_modifierMask;
/** Ignores window size messages (when window is dragged). */
bool m_ignoreWindowSizedMessages;
/** Stores the mouse cursor delta due to setting a new cursor position
* Needed because cocoa event delta cursor move takes setCursorPosition changes too.
*/
GHOST_TInt32 m_cursorDelta_x, m_cursorDelta_y;
/** Multitouch trackpad availability */
bool m_hasMultiTouchTrackpad;
/** Multitouch gesture in progress, useful to distinguish trackpad from mouse scroll events */
bool m_isGestureInProgress;
NSAutoreleasePool* m_pool;
};
#endif // _GHOST_SYSTEM_COCOA_H_

@ -466,19 +466,12 @@ extern "C" {
struct bContext;
struct wmOperator;
extern int fromcocoa_request_qtcodec_settings(bContext *C, wmOperator *op);
int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
{
int result;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
result = fromcocoa_request_qtcodec_settings(C, op);
[pool drain];
return result;
}
};
int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
{
return fromcocoa_request_qtcodec_settings(C, op);
}
} // "C"
#endif
@ -541,6 +534,8 @@ int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
GHOST_SystemCocoa::GHOST_SystemCocoa()
{
m_pool = [[NSAutoreleasePool alloc] init];
int mib[2];
struct timeval boottime;
size_t len;
@ -556,7 +551,7 @@ GHOST_SystemCocoa::GHOST_SystemCocoa()
m_tablet_pen_mode = GHOST_kTabletModeNone;
m_outsideLoopEventProcessed = false;
m_needDelayedApplicationBecomeActiveEventProcessing = false;
m_displayManager = new GHOST_DisplayManagerCocoa ();
m_displayManager = new GHOST_DisplayManagerCocoa;
GHOST_ASSERT(m_displayManager, "GHOST_SystemCocoa::GHOST_SystemCocoa(): m_displayManager==0\n");
m_displayManager->initialize();
@ -602,7 +597,6 @@ GHOST_TSuccess GHOST_SystemCocoa::init()
m_ndofManager = new GHOST_NDOFManagerCocoa(*this);
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (NSApp == nil) {
[NSApplication sharedApplication];
@ -666,8 +660,6 @@ GHOST_TSuccess GHOST_SystemCocoa::init()
}
[NSApp finishLaunching];
[pool drain];
}
return success;
}
@ -696,18 +688,12 @@ GHOST_TUns8 GHOST_SystemCocoa::getNumDisplays() const
{
//Note that OS X supports monitor hot plug
// We do not support multiple monitors at the moment
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
GHOST_TUns8 count = [[NSScreen screens] count];
[pool drain];
return count;
return [[NSScreen screens] count];
}
void GHOST_SystemCocoa::getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//Get visible frame, that is frame excluding dock and top menu bar
NSRect frame = [[NSScreen mainScreen] visibleFrame];
@ -717,8 +703,6 @@ void GHOST_SystemCocoa::getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns
width = contentRect.size.width;
height = contentRect.size.height;
[pool drain];
}
@ -735,7 +719,6 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow(
const GHOST_TEmbedderWindowID parentWindow
)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
GHOST_IWindow* window = 0;
//Get the available rect for including window contents
@ -768,7 +751,6 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow(
else {
GHOST_PRINT("GHOST_SystemCocoa::createWindow(): could not create window\n");
}
[pool drain];
return window;
}
@ -789,8 +771,6 @@ GHOST_TSuccess GHOST_SystemCocoa::endFullScreen(void)
return currentWindow->setState(GHOST_kWindowStateNormal);
}
/**
* @note : returns coordinates in Cocoa screen coordinates
@ -835,7 +815,7 @@ GHOST_TSuccess GHOST_SystemCocoa::setMouseCursorPosition(float xf, float yf)
GHOST_WindowCocoa* window = (GHOST_WindowCocoa*)m_windowManager->getActiveWindow();
if (!window) return GHOST_kFailure;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSScreen *windowScreen = window->getScreen();
NSRect screenRect = [windowScreen frame];
@ -848,7 +828,7 @@ GHOST_TSuccess GHOST_SystemCocoa::setMouseCursorPosition(float xf, float yf)
CGDisplayMoveCursorToPoint((CGDirectDisplayID)[[[windowScreen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue], CGPointMake(xf, yf));
[pool drain];
// [pool drain];
return GHOST_kSuccess;
}
@ -995,8 +975,6 @@ bool GHOST_SystemCocoa::processEvents(bool waitForEvent)
}
} while (event != nil);
[pool drain];
if (m_needDelayedApplicationBecomeActiveEventProcessing)
handleApplicationBecomeActiveEvent();
@ -1005,6 +983,9 @@ bool GHOST_SystemCocoa::processEvents(bool waitForEvent)
return true;
}
[pool drain]; // for this event processing thread
[m_pool drain]; // for main thread
return anyProcessed;
}
@ -1404,9 +1385,6 @@ GHOST_TSuccess GHOST_SystemCocoa::handleTabletProximity(void *eventPtr)
return GHOST_kFailure;
}
// don't involve the window!
// GHOST_TabletData& ct = window->GetCocoaTabletData();
GHOST_TTabletMode active_tool;
int* tool_id_ptr;
@ -1438,11 +1416,6 @@ GHOST_TSuccess GHOST_SystemCocoa::handleTabletProximity(void *eventPtr)
m_tablet_pen_mode = active_tool;
// ct.Active = active_tool;
// ct.Pressure = (active_tool == GHOST_kTabletModeNone) ? /*mouse*/ 1 : /*pen*/ 0;
// ct.Xtilt = 0;
// ct.Ytilt = 0;
// this is a good place to remember the tool's capabilities
}
else {
@ -1450,11 +1423,6 @@ GHOST_TSuccess GHOST_SystemCocoa::handleTabletProximity(void *eventPtr)
*tool_id_ptr = TOOL_ID_NONE;
m_tablet_pen_mode = GHOST_kTabletModeNone;
// ct.Active = GHOST_kTabletModeNone;
// ct.Pressure = 0;
// ct.Xtilt = 0;
// ct.Ytilt = 0;
}
return GHOST_kSuccess;
@ -1485,16 +1453,6 @@ GHOST_TSuccess GHOST_SystemCocoa::handleTabletEvent(void *eventPtr)
return GHOST_kFailure;
}
/*
// don't involve the window!
GHOST_TabletData& ct = window->GetCocoaTabletData();
ct.Pressure = [event pressure];
NSPoint tilt = [event tilt];
ct.Xtilt = tilt.x;
ct.Ytilt = tilt.y;
*/
switch ([event type])
{
case NSLeftMouseDown:
@ -1814,12 +1772,9 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
GHOST_TUns8 * temp_buff;
size_t pastedTextSize;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
if (pasteBoard == nil) {
[pool drain];
return NULL;
}
@ -1830,14 +1785,12 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
availableTypeFromArray:supportedTypes];
if (bestType == nil) {
[pool drain];
return NULL;
}
NSString * textPasted = [pasteBoard stringForType:NSStringPboardType];
if (textPasted == nil) {
[pool drain];
return NULL;
}
@ -1846,7 +1799,6 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1);
if (temp_buff == NULL) {
[pool drain];
return NULL;
}
@ -1854,8 +1806,6 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
temp_buff[pastedTextSize] = '\0';
[pool drain];
if(temp_buff) {
return temp_buff;
} else {
@ -1869,12 +1819,9 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
if(selection) {return;} // for copying the selection, used on X11
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
if (pasteBoard == nil) {
[pool drain];
return;
}
@ -1885,8 +1832,6 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
textToCopy = [NSString stringWithCString:buffer encoding:NSISOLatin1StringEncoding];
[pasteBoard setString:textToCopy forType:NSStringPboardType];
[pool drain];
}
#pragma mark Base directories retrieval
@ -1894,7 +1839,6 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
{
static GHOST_TUns8 tempPath[512] = "";
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *basePath;
NSArray *paths;
@ -1903,20 +1847,17 @@ const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
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;
@ -1925,31 +1866,26 @@ const GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const
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;
}

@ -25,6 +25,7 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
/**
* @file GHOST_WindowCocoa.h
* Declaration of GHOST_WindowCocoa class.
@ -34,13 +35,14 @@
#define _GHOST_WINDOW_COCOA_H_
#ifndef __APPLE__
#error Apple OSX only!
#endif // __APPLE__
#error Apple OSX only!
#endif
#include "GHOST_Window.h"
#include "STR_String.h"
@class CocoaWindow;
@class NSAutoreleasePool;
class GHOST_SystemCocoa;
@ -52,8 +54,8 @@ class GHOST_SystemCocoa;
* which is called the gutter.
* When OpenGL contexts are active, GHOST will use AGL_BUFFER_RECT to prevent
* OpenGL drawing outside the reduced client rectangle.
* @author Maarten Gribnau
* @date May 23, 2001
* @author Maarten Gribnau
* @date May 23, 2001
*/
class GHOST_WindowCocoa : public GHOST_Window {
public:
@ -61,16 +63,16 @@ public:
* Constructor.
* Creates a new window and opens it.
* To check if the window was created properly, use the getValid() method.
* @param systemCocoa The associated system class to forward events to
* @param title The text shown in the title bar of the window.
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state the window is initially opened with.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
* @param systemCocoa The associated system class to forward events to
* @param title The text shown in the title bar of the window.
* @param left The coordinate of the left edge of the window.
* @param top The coordinate of the top edge of the window.
* @param width The width the window.
* @param height The height the window.
* @param state The state the window is initially opened with.
* @param type The type of drawing context installed in this window.
* @param stereoVisual Stereo visual for quad buffered stereo.
* @param numOfAASamples Number of samples used for AA (zero if no AA)
*/
GHOST_WindowCocoa(
GHOST_SystemCocoa *systemCocoa,
@ -89,121 +91,121 @@ public:
* Destructor.
* Closes the window and disposes resources allocated.
*/
virtual ~GHOST_WindowCocoa();
~GHOST_WindowCocoa();
/**
* Returns indication as to whether the window is valid.
* @return The validity of the window.
*/
virtual bool getValid() const;
bool getValid() const;
/**
* Returns the associated NSWindow object
* @return The associated NSWindow object
*/
virtual void* getOSWindow() const;
void* getOSWindow() const;
/**
* Sets the title displayed in the title bar.
* @param title The title to display in the title bar.
*/
virtual void setTitle(const STR_String& title);
void setTitle(const STR_String& title);
/**
* Returns the title displayed in the title bar.
* @param title The title displayed in the title bar.
*/
virtual void getTitle(STR_String& title) const;
void getTitle(STR_String& title) const;
/**
* Returns the window rectangle dimensions.
* The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
* @param bounds The bounding rectangle of the window.
*/
virtual void getWindowBounds(GHOST_Rect& bounds) const;
void getWindowBounds(GHOST_Rect& bounds) const;
/**
* Returns the client rectangle dimensions.
* The left and top members of the rectangle are always zero.
* @param bounds The bounding rectangle of the cleient area of the window.
*/
virtual void getClientBounds(GHOST_Rect& bounds) const;
void getClientBounds(GHOST_Rect& bounds) const;
/**
* Resizes client rectangle width.
* @param width The new width of the client area of the window.
*/
virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
/**
* Resizes client rectangle height.
* @param height The new height of the client area of the window.
*/
virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
/**
* Resizes client rectangle.
* @param width The new width of the client area of the window.
* @param height The new height of the client area of the window.
* @param width The new width of the client area of the window.
* @param height The new height of the client area of the window.
*/
virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
/**
* Returns the state of the window (normal, minimized, maximized).
* @return The state of the window.
*/
virtual GHOST_TWindowState getState() const;
GHOST_TWindowState getState() const;
/**
* Sets the window "modified" status, indicating unsaved changes
* @param isUnsavedChanges Unsaved changes or not
* @return Indication of success.
*/
virtual GHOST_TSuccess setModifiedState(bool isUnsavedChanges);
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param inX The x-coordinate on the screen.
* @param inY The y-coordinate on the screen.
* @param outX The x-coordinate in the client rectangle.
* @param outY The y-coordinate in the client rectangle.
*/
virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
GHOST_TSuccess setModifiedState(bool isUnsavedChanges);
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param inX The x-coordinate in the client rectangle.
* @param inY The y-coordinate in the client rectangle.
* @param outX The x-coordinate on the screen.
* @param outY The y-coordinate on the screen.
* @param inX The x-coordinate on the screen.
* @param inY The y-coordinate on the screen.
* @param outX The x-coordinate in the client rectangle.
* @param outY The y-coordinate in the client rectangle.
*/
virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
/**
* Converts a point in screen coordinates to client rectangle coordinates
* @param inX The x-coordinate in the client rectangle.
* @param inY The y-coordinate in the client rectangle.
* @param outX The x-coordinate on the screen.
* @param outY The y-coordinate on the screen.
*/
void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
/**
* Gets the screen the window is displayed in
* @return The NSScreen object
*/
NSScreen* getScreen();
/**
* Sets the state of the window (normal, minimized, maximized).
* @param state The state of the window.
* @return Indication of success.
* @param state The state of the window.
* @return Indication of success.
*/
virtual GHOST_TSuccess setState(GHOST_TWindowState state);
GHOST_TSuccess setState(GHOST_TWindowState state);
/**
* Sets the order of the window (bottom, top).
* @param order The order of the window.
* @return Indication of success.
* @param order The order of the window.
* @return Indication of success.
*/
virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
/**
* Swaps front and back buffers of a window.
* @return A boolean success indicator.
* @return A boolean success indicator.
*/
virtual GHOST_TSuccess swapBuffers();
GHOST_TSuccess swapBuffers();
/**
* Updates the drawing context of this window. Needed
@ -216,87 +218,84 @@ public:
* Activates the drawing context of this window.
* @return A boolean success indicator.
*/
virtual GHOST_TSuccess activateDrawingContext();
GHOST_TSuccess activateDrawingContext();
virtual void loadCursor(bool visible, GHOST_TStandardCursor cursor) const;
const GHOST_TabletData* GetTabletData()
{ return NULL; }
void loadCursor(bool visible, GHOST_TStandardCursor cursor) const;
/**
* Sets the progress bar value displayed in the window/application icon
* @param progress The progress % (0.0 to 1.0)
* @param progress The progress % (0.0 to 1.0)
*/
virtual GHOST_TSuccess setProgressBar(float progress);
GHOST_TSuccess setProgressBar(float progress);
/**
* Hides the progress bar icon
*/
virtual GHOST_TSuccess endProgressBar();
GHOST_TSuccess endProgressBar();
protected:
/**
* Tries to install a rendering context in this window.
* @param type The type of rendering context installed.
* @return Indication as to whether installation has succeeded.
* @param type The type of rendering context installed.
* @return Indication as to whether installation has succeeded.
*/
virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
/**
* Removes the current drawing context.
* @return Indication as to whether removal has succeeded.
* @return Indication as to whether removal has succeeded.
*/
virtual GHOST_TSuccess removeDrawingContext();
GHOST_TSuccess removeDrawingContext();
/**
* Invalidates the contents of this window.
* @return Indication of success.
* @return Indication of success.
*/
virtual GHOST_TSuccess invalidate();
GHOST_TSuccess invalidate();
/**
* Sets the cursor visibility on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorVisibility(bool visible);
GHOST_TSuccess setWindowCursorVisibility(bool visible);
/**
* Sets the cursor grab on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color);
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
/**
* Sets the cursor shape on the window using
* native window system calls.
*/
GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color);
GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
/** The window containing the OpenGL view */
CocoaWindow *m_window;
/** The openGL view */
/** The window containing the OpenGL view */
CocoaWindow *m_window;
/** The OpenGL view */
NSOpenGLView *m_openGLView;
/** The opgnGL drawing context */
/** The OpenGL drawing context */
NSOpenGLContext *m_openGLContext;
/** The mother SystemCocoa class to send events */
GHOST_SystemCocoa *m_systemCocoa;
/** The first created OpenGL context (for sharing display lists) */
static NSOpenGLContext *s_firstOpenGLcontext;
NSCursor* m_customCursor;
/** The mother SystemCocoa class to send events */
GHOST_SystemCocoa *m_ghostSystem;
NSCursor* m_customCursor;
};
#endif // _GHOST_WINDOW_COCOA_H_

File diff suppressed because it is too large Load Diff