summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorGeenz <geenz@geenzo.com>2013-01-08 16:22:54 -0500
committerGeenz <geenz@geenzo.com>2013-01-08 16:22:54 -0500
commit09b07e3619a71f142c1a3af41244d756e1230142 (patch)
tree5474f6c3a557693794714eaa7247a87edb6df8b1 /indra
parent9ce3ab1a5248423eeea4d843bfb8407ed62b305e (diff)
Big change set:
- LLAppDelegate header relocated to LLWindow. Definition is still present in secondlife-bin (for compatibility reasons when loading a nib). - Return key handling fixed. - Command key now acts the same as the control key by issuing control character codes when the command key is pressed. - We now retrieve the window pointer directly from the app delegate in LLWindow.
Diffstat (limited to 'indra')
-rw-r--r--indra/llwindow/CMakeLists.txt1
-rw-r--r--indra/llwindow/llappdelegate-objc.h (renamed from indra/newview/llappviewermacosx-delegate.h)2
-rw-r--r--indra/llwindow/llkeyboardmacosx.cpp35
-rw-r--r--indra/llwindow/llopenglview-objc.h5
-rw-r--r--indra/llwindow/llopenglview-objc.mm113
-rw-r--r--indra/llwindow/llwindowmacosx-objc.h11
-rw-r--r--indra/llwindow/llwindowmacosx-objc.mm56
-rw-r--r--indra/llwindow/llwindowmacosx.cpp22
-rwxr-xr-xindra/newview/CMakeLists.txt8
-rw-r--r--indra/newview/llappdelegate-objc.mm (renamed from indra/newview/llappviewermacosx-delegate.mm)4
-rw-r--r--indra/newview/llappviewermacosx-objc.h19
-rw-r--r--indra/newview/llappviewermacosx-objc.mm20
-rw-r--r--indra/newview/llappviewermacosx.cpp2
13 files changed, 157 insertions, 141 deletions
diff --git a/indra/llwindow/CMakeLists.txt b/indra/llwindow/CMakeLists.txt
index 8a38db751e..84e0169826 100644
--- a/indra/llwindow/CMakeLists.txt
+++ b/indra/llwindow/CMakeLists.txt
@@ -82,6 +82,7 @@ if (DARWIN)
llwindowmacosx.h
llwindowmacosx-objc.h
llopenglview-objc.h
+ llappdelegate-objc.h
)
# We use a bunch of deprecated system APIs.
diff --git a/indra/newview/llappviewermacosx-delegate.h b/indra/llwindow/llappdelegate-objc.h
index 848ccbde62..56b7a30797 100644
--- a/indra/newview/llappviewermacosx-delegate.h
+++ b/indra/llwindow/llappdelegate-objc.h
@@ -8,7 +8,7 @@
#import <Cocoa/Cocoa.h>
#import "llopenglview-objc.h"
-#include "llappviewermacosx-objc.h"
+#include "llwindowmacosx-objc.h"
@interface LLAppDelegate : NSObject <NSApplicationDelegate> {
LLNSWindow *window;
diff --git a/indra/llwindow/llkeyboardmacosx.cpp b/indra/llwindow/llkeyboardmacosx.cpp
index 077ebea909..3db94e8835 100644
--- a/indra/llwindow/llkeyboardmacosx.cpp
+++ b/indra/llwindow/llkeyboardmacosx.cpp
@@ -167,13 +167,15 @@ void LLKeyboardMacOSX::resetMaskKeys()
// MBW -- XXX -- This mirrors the operation of the Windows version of resetMaskKeys().
// It looks a bit suspicious, as it won't correct for keys that have been released.
// Is this the way it's supposed to work?
+
+ // We apply the modifier masks directly within getModifiers. So check to see which masks we've applied.
if(mask & MAC_SHIFT_KEY)
{
mKeyLevel[KEY_SHIFT] = TRUE;
}
- if(mask & (MAC_CTRL_KEY))
+ if(mask & MAC_CTRL_KEY)
{
mKeyLevel[KEY_CONTROL] = TRUE;
}
@@ -198,25 +200,9 @@ static BOOL translateKeyMac(const U16 key, const U32 mask, KEY &outKey, U32 &out
MASK LLKeyboardMacOSX::updateModifiers(const U32 mask)
{
- // translate the mask
- MASK out_mask = 0;
-
- if(mask & MAC_SHIFT_KEY)
- {
- out_mask |= MASK_SHIFT;
- }
-
- if(mask & MAC_CTRL_KEY || mask & MAC_CMD_KEY)
- {
- out_mask |= MASK_CONTROL;
- }
-
- if(mask & MAC_ALT_KEY)
- {
- out_mask |= MASK_ALT;
- }
-
- return out_mask;
+ // This is handled for us in LLNSWindow on OS X.
+
+ return mask;
}
BOOL LLKeyboardMacOSX::handleKeyDown(const U16 key, const U32 mask)
@@ -231,12 +217,7 @@ BOOL LLKeyboardMacOSX::handleKeyDown(const U16 key, const U32 mask)
{
handled = handleTranslatedKeyDown(translated_key, translated_mask);
}
- if (!handled)
- {
- LL_INFOS("Keyboard") << "Unhandled key: " << mTranslateKeyMap[key] << LL_ENDL;
- } else {
- LL_INFOS("Keyboard") << "Handled key: " << mTranslateKeyMap[key] << LL_ENDL;
- }
+
return handled;
}
@@ -272,7 +253,7 @@ MASK LLKeyboardMacOSX::currentMask(BOOL for_mouse_event)
if (mask & MAC_CMD_KEY) result |= MASK_CONTROL;
}
- return result;
+ return mask;
}
void LLKeyboardMacOSX::scanKeyboard()
diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h
index 20589e321d..8412621392 100644
--- a/indra/llwindow/llopenglview-objc.h
+++ b/indra/llwindow/llopenglview-objc.h
@@ -40,8 +40,3 @@
}
@end
-
-void setLLNSWindowRef(LLNSWindow* window);
-void setLLOpenGLViewRef(LLOpenGLView* view);
-LLNSWindow* winRef;
-LLOpenGLView* glviewRef;
diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm
index e5e198b856..d91601152b 100644
--- a/indra/llwindow/llopenglview-objc.mm
+++ b/indra/llwindow/llopenglview-objc.mm
@@ -132,62 +132,72 @@
- (void) mouseDragged:(NSEvent *)theEvent
{
- [super mouseDragged:theEvent];
+ [_window mouseDragged:theEvent];
}
- (void) scrollWheel:(NSEvent *)theEvent
{
- [super scrollWheel:theEvent];
+ [_window scrollWheel:theEvent];
}
- (void) mouseDown:(NSEvent *)theEvent
{
- [super mouseDown:theEvent];
+ [_window mouseDown:theEvent];
}
- (void) mouseUp:(NSEvent *)theEvent
{
- [super mouseUp:theEvent];
+ [_window mouseUp:theEvent];
}
- (void) rightMouseDown:(NSEvent *)theEvent
{
- [super rightMouseDown:theEvent];
+ [_window rightMouseDown:theEvent];
}
- (void) rightMouseUp:(NSEvent *)theEvent
{
- [super rightMouseUp:theEvent];
+ [_window rightMouseUp:theEvent];
+}
+
+- (void) otherMouseDown:(NSEvent *)theEvent
+{
+ [_window otherMouseDown:theEvent];
+}
+
+- (void) otherMouseUp:(NSEvent *)theEvent
+{
+ [_window otherMouseUp:theEvent];
}
- (void) keyUp:(NSEvent *)theEvent
{
- [super keyUp:theEvent];
+ [_window keyUp:theEvent];
}
- (void) keyDown:(NSEvent *)theEvent
{
- [super keyDown:theEvent];
+ [_window keyDown:theEvent];
}
- (void) mouseMoved:(NSEvent *)theEvent
{
- [super mouseMoved:theEvent];
+ [_window mouseMoved:theEvent];
}
- (void) flagsChanged:(NSEvent *)theEvent
{
- [super flagsChanged:theEvent];
+ [_window flagsChanged:theEvent];
}
- (BOOL) becomeFirstResponder
{
- return [super becomeFirstResponder];
+ return [_window becomeFirstResponder];
}
- (BOOL) resignFirstResponder
{
- return [super resignFirstResponder];
+ return [_window resignFirstResponder];
}
@end
@@ -200,58 +210,99 @@
- (id) init
{
+ //[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType, nil]];
return self;
}
- (void) keyDown:(NSEvent *)theEvent
{
- callKeyDown([theEvent keyCode], [theEvent modifierFlags]);
-
+ callKeyDown([theEvent keyCode], mModifiers);
NSString *chars = [theEvent characters];
for (uint i = 0; i < [chars length]; i++)
{
// Enter and Return are special cases.
unichar returntest = [chars characterAtIndex:i];
- if ((returntest == NSCarriageReturnCharacter || returntest == NSEnterCharacter) && !([theEvent modifierFlags] & NSCommandKeyMask) && !([theEvent modifierFlags] & NSAlternateKeyMask) && !([theEvent modifierFlags] & NSControlKeyMask))
+ if ((returntest == NSCarriageReturnCharacter || returntest == NSEnterCharacter) &&
+ !([theEvent modifierFlags] & NSCommandKeyMask) &&
+ !([theEvent modifierFlags] & NSAlternateKeyMask) &&
+ !([theEvent modifierFlags] & NSControlKeyMask))
{
- callUnicodeCallback(returntest, 0);
+ callUnicodeCallback(13, 0);
} else {
- callUnicodeCallback([chars characterAtIndex:i], [theEvent modifierFlags]);
+ // The command key being pressed is also a special case.
+ // Control + <character> produces an ASCII control character code.
+ // Command + <character> produces just the character's code.
+ // Check to see if the command key is pressed, then filter through the different character ranges that are relevant to control characters, and subtract the appropriate range.
+ if ([theEvent modifierFlags] & NSCommandKeyMask)
+ {
+ if (returntest >= 64 && returntest <= 95)
+ {
+ callUnicodeCallback(returntest - 63, mModifiers);
+ } else if (returntest >= 97 && returntest <= 122)
+ {
+ callUnicodeCallback(returntest - 96, mModifiers);
+ }
+ } else {
+ callUnicodeCallback(returntest, mModifiers);
+ }
}
}
}
- (void) keyUp:(NSEvent *)theEvent {
- callKeyUp([theEvent keyCode], [theEvent modifierFlags]);
+ callKeyUp([theEvent keyCode], mModifiers);
}
- (void)flagsChanged:(NSEvent *)theEvent {
- mModifiers = [theEvent modifierFlags];
+ uint modifiers = [theEvent modifierFlags];
+
+ // Filter through our modifier keys, and only pick out the ones we care about.
+
+ mModifiers = 0;
+ if (modifiers & NSCommandKeyMask)
+ {
+ mModifiers |= 0x0001;
+ }
+
+ if (modifiers & NSAlternateKeyMask)
+ {
+ mModifiers |= 0x0002;
+ }
+
+ if (modifiers & NSShiftKeyMask)
+ {
+ mModifiers |= 0x0004;
+ }
+
+ if (modifiers & NSControlKeyMask)
+ {
+ mModifiers |= 0x0001;
+ }
}
- (void) mouseDown:(NSEvent *)theEvent
{
if ([theEvent clickCount] >= 2)
{
- callDoubleClick(mMousePos, [theEvent modifierFlags]);
+ callDoubleClick(mMousePos, mModifiers);
} else if ([theEvent clickCount] == 1) {
- callLeftMouseDown(mMousePos, [theEvent modifierFlags]);
+ callLeftMouseDown(mMousePos, mModifiers);
}
}
- (void) mouseUp:(NSEvent *)theEvent
{
- callLeftMouseUp(mMousePos, [theEvent modifierFlags]);
+ callLeftMouseUp(mMousePos, mModifiers);
}
- (void) rightMouseDown:(NSEvent *)theEvent
{
- callRightMouseDown(mMousePos, [theEvent modifierFlags]);
+ callRightMouseDown(mMousePos, mModifiers);
}
- (void) rightMouseUp:(NSEvent *)theEvent
{
- callRightMouseUp(mMousePos, [theEvent modifierFlags]);
+ callRightMouseUp(mMousePos, mModifiers);
}
- (void)mouseMoved:(NSEvent *)theEvent
@@ -292,12 +343,12 @@
- (void) otherMouseDown:(NSEvent *)theEvent
{
- callMiddleMouseDown(mMousePos, 0);
+ callMiddleMouseDown(mMousePos, mModifiers);
}
- (void) otherMouseUp:(NSEvent *)theEvent
{
- callMiddleMouseUp(mMousePos, 0);
+ callMiddleMouseUp(mMousePos, mModifiers);
}
- (void) otherMouseDragged:(NSEvent *)theEvent
@@ -330,13 +381,3 @@
}
@end
-
-void setLLNSWindowRef(LLNSWindow* window)
-{
- winRef = window;
-}
-
-void setLLOpenGLViewRef(LLOpenGLView* view)
-{
- glviewRef = view;
-}
diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h
index 414491f948..57b3d11296 100644
--- a/indra/llwindow/llwindowmacosx-objc.h
+++ b/indra/llwindow/llwindowmacosx-objc.h
@@ -38,8 +38,19 @@ typedef void *CursorRef;
typedef void *NSWindowRef;
typedef void *GLViewRef;
+// These are defined in llappviewermacosx.cpp.
+bool initViewer();
+void handleQuit();
+bool runMainLoop();
+void initMainLoop();
+void cleanupViewer();
+
/* Defined in llwindowmacosx-objc.mm: */
+int createNSApp(int argc, const char **argv);
void setupCocoa();
+bool pasteBoardAvailable();
+bool copyToPBoard(const unsigned short *str, unsigned int len);
+const unsigned short *copyFromPBoard();
CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY);
short releaseImageCursor(CursorRef ref);
short setImageCursor(CursorRef ref);
diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm
index 5a024eda46..1a64c94b2d 100644
--- a/indra/llwindow/llwindowmacosx-objc.mm
+++ b/indra/llwindow/llwindowmacosx-objc.mm
@@ -29,6 +29,7 @@
#include <Cocoa/Cocoa.h>
#include "llwindowmacosx-objc.h"
#include "llopenglview-objc.h"
+#include "llappdelegate-objc.h"
/*
* These functions are broken out into a separate file because the
@@ -37,6 +38,11 @@
* linden headers with any objective-C++ source.
*/
+int createNSApp(int argc, const char *argv[])
+{
+ return NSApplicationMain(argc, argv);
+}
+
void setupCocoa()
{
static bool inited = false;
@@ -49,15 +55,6 @@ void setupCocoa()
// ie. running './secondlife -set Language fr' would cause a pop-up saying can't open document 'fr'
// when init'ing the Cocoa App window.
[[NSUserDefaults standardUserDefaults] setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
-
- // This is a bit of voodoo taken from the Apple sample code "CarbonCocoa_PictureCursor":
- // http://developer.apple.com/samplecode/CarbonCocoa_PictureCursor/index.html
-
- // Needed for Carbon based applications which call into Cocoa
- // NSApplicationLoad();
-
- // Must first call [[[NSWindow alloc] init] release] to get the NSWindow machinery set up so that NSCursor can use a window to cache the cursor image
- //[[[NSWindow alloc] init] release];
[pool release];
@@ -65,6 +62,38 @@ void setupCocoa()
}
}
+bool copyToPBoard(const unsigned short *str, unsigned int len)
+{
+ NSPasteboard *pboard = [NSPasteboard generalPasteboard];
+ [pboard clearContents];
+
+ NSArray *contentsToPaste = [[NSArray alloc] initWithObjects:[NSString stringWithCharacters:str length:len], nil];
+
+ return [pboard writeObjects:contentsToPaste];
+}
+
+bool pasteBoardAvailable()
+{
+ NSArray *classArray = [NSArray arrayWithObject:[NSString class]];
+ return [[NSPasteboard generalPasteboard] canReadObjectForClasses:classArray options:[NSDictionary dictionary]];
+}
+
+const unsigned short *copyFromPBoard()
+{
+ NSPasteboard *pboard = [NSPasteboard generalPasteboard];
+ NSArray *classArray = [NSArray arrayWithObject:[NSString class]];
+ NSString *str = NULL;
+ BOOL ok = [pboard canReadObjectForClasses:classArray options:[NSDictionary dictionary]];
+ if (ok)
+ {
+ NSArray *objToPaste = [pboard readObjectsForClasses:classArray options:[NSDictionary dictionary]];
+ str = [objToPaste objectAtIndex:0];
+ }
+ unichar* temp = (unichar*)calloc([str length], sizeof(unichar));
+ [str getCharacters:temp];
+ return temp;
+}
+
CursorRef createImageCursor(const char *fullpath, int hotspotX, int hotspotY)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@@ -287,15 +316,12 @@ void removeGLView(GLViewRef view)
NSWindowRef getMainAppWindow()
{
- [(LLNSWindow*)winRef setAcceptsMouseMovedEvents:TRUE];
+ LLNSWindow *winRef = [(LLAppDelegate*)[[NSApplication sharedApplication] delegate] window];
+
+ [winRef setAcceptsMouseMovedEvents:TRUE];
return winRef;
}
-GLViewRef getGLView()
-{
- return glviewRef;
-}
-
unsigned int getModifiers()
{
return [NSEvent modifierFlags];
diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp
index 902391e170..93b9f4c484 100644
--- a/indra/llwindow/llwindowmacosx.cpp
+++ b/indra/llwindow/llwindowmacosx.cpp
@@ -1029,25 +1029,27 @@ void LLWindowMacOSX::flashIcon(F32 seconds)
BOOL LLWindowMacOSX::isClipboardTextAvailable()
{
- BOOL result = false;
- // TODO: Clipboard support.
- return result;
+ return pasteBoardAvailable();
}
BOOL LLWindowMacOSX::pasteTextFromClipboard(LLWString &dst)
-{
- BOOL result = false;
-
- // TODO: Clipboard support.
-
- return result;
+{
+ llutf16string str(copyFromPBoard());
+ dst = utf16str_to_wstring(str);
+ if (dst != L"")
+ {
+ return true;
+ } else {
+ return false;
+ }
}
BOOL LLWindowMacOSX::copyTextToClipboard(const LLWString &s)
{
BOOL result = false;
+ llutf16string utf16str = wstring_to_utf16str(s);
- // TODO: Clipboard support.
+ result = copyToPBoard(utf16str.data(), utf16str.length());
return result;
}
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index 73f5ecc38c..c60940f93c 100755
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -1231,10 +1231,9 @@ source_group("CMake Rules" FILES ViewerInstall.cmake)
if (DARWIN)
LIST(APPEND viewer_SOURCE_FILES llappviewermacosx.cpp)
- LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-objc.h)
- LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-objc.mm)
- LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-delegate.h)
- LIST(APPEND viewer_SOURCE_FILES llappviewermacosx-delegate.mm)
+
+ # This should be compiled with the viewer.
+ LIST(APPEND viewer_SOURCE_FILES llappdelegate-objc.mm)
find_library(AGL_LIBRARY AGL)
find_library(APPKIT_LIBRARY AppKit)
@@ -1532,6 +1531,7 @@ if (FMOD)
if (DARWIN)
set(fmodwrapper_SOURCE_FILES fmodwrapper.cpp)
add_library(fmodwrapper SHARED ${fmodwrapper_SOURCE_FILES})
+ find_library(CARBON_LIBRARY Carbon)
set(fmodwrapper_needed_LIBRARIES ${FMOD_LIBRARY} ${CARBON_LIBRARY})
set_target_properties(
fmodwrapper
diff --git a/indra/newview/llappviewermacosx-delegate.mm b/indra/newview/llappdelegate-objc.mm
index 7baeeb1de8..f5143d7578 100644
--- a/indra/newview/llappviewermacosx-delegate.mm
+++ b/indra/newview/llappdelegate-objc.mm
@@ -6,7 +6,7 @@
//
//
-#import "llappviewermacosx-delegate.h"
+#import "llappdelegate-objc.h"
@implementation LLAppDelegate
@@ -21,8 +21,6 @@
{
frameTimer = nil;
- setLLNSWindowRef([self window]);
-
if (initViewer())
{
frameTimer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(mainLoop) userInfo:nil repeats:YES];
diff --git a/indra/newview/llappviewermacosx-objc.h b/indra/newview/llappviewermacosx-objc.h
deleted file mode 100644
index ed9017ca5d..0000000000
--- a/indra/newview/llappviewermacosx-objc.h
+++ /dev/null
@@ -1,19 +0,0 @@
-//
-// NSObject_llappviewermacosx_objc.h
-// SecondLife
-//
-// Created by Geenz on 12/16/12.
-//
-//
-
-#include <boost/tr1/functional.hpp>
-typedef std::tr1::function<void()> VoidCallback;
-typedef void* ViewerAppRef;
-
-int createNSApp(int argc, const char **argv);
-
-bool initViewer();
-void handleQuit();
-bool runMainLoop();
-void initMainLoop();
-void cleanupViewer(); \ No newline at end of file
diff --git a/indra/newview/llappviewermacosx-objc.mm b/indra/newview/llappviewermacosx-objc.mm
deleted file mode 100644
index ca2090b790..0000000000
--- a/indra/newview/llappviewermacosx-objc.mm
+++ /dev/null
@@ -1,20 +0,0 @@
-//
-// llappviewermacosx.m
-// SecondLife
-//
-// Created by Geenz on 12/12/12.
-//
-//
-
-#import <Cocoa/Cocoa.h>
-#import <ApplicationServices/ApplicationServices.h>
-#include "llappviewermacosx-objc.h"
-#import "llappviewermacosx-delegate.h"
-
-int createNSApp(int argc, const char *argv[])
-{
- return NSApplicationMain(argc, argv);
-}
-
-
-
diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp
index 6e7b91347b..b199405a66 100644
--- a/indra/newview/llappviewermacosx.cpp
+++ b/indra/newview/llappviewermacosx.cpp
@@ -31,7 +31,7 @@
#endif
#include "llappviewermacosx.h"
-#include "llappviewermacosx-objc.h"
+#include "llwindowmacosx-objc.h"
#include "llcommandlineparser.h"
#include "llmemtype.h"