Cleanup: move CocoaOpenGLView into own header

This commit is contained in:
Brecht Van Lommel 2019-06-01 18:02:46 +02:00
parent 593eab66b5
commit 01a5e087aa
2 changed files with 282 additions and 259 deletions

View file

@ -262,261 +262,8 @@
@end
#pragma mark NSOpenGLView subclass
//We need to subclass it in order to give Cocoa the feeling key events are trapped
@interface CocoaOpenGLView : NSOpenGLView <NSTextInput>
{
GHOST_SystemCocoa *systemCocoa;
GHOST_WindowCocoa *associatedWindow;
bool composing;
NSString *composing_text;
bool immediate_draw;
}
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa
windowCocoa:(GHOST_WindowCocoa *)winCocoa;
@end
@implementation CocoaOpenGLView
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa
windowCocoa:(GHOST_WindowCocoa *)winCocoa
{
systemCocoa = sysCocoa;
associatedWindow = winCocoa;
composing = false;
composing_text = nil;
immediate_draw = false;
}
- (BOOL)acceptsFirstResponder
{
return YES;
}
// The trick to prevent Cocoa from complaining (beeping)
- (void)keyDown:(NSEvent *)event
{
systemCocoa->handleKeyEvent(event);
/* Start or continue composing? */
if ([[event characters] length] == 0 || [[event charactersIgnoringModifiers] length] == 0 ||
composing) {
composing = YES;
// interpret event to call insertText
NSMutableArray *events;
events = [[NSMutableArray alloc] initWithCapacity:1];
[events addObject:event];
[self interpretKeyEvents:events]; // calls insertText
[events removeObject:event];
[events release];
return;
}
}
- (void)keyUp:(NSEvent *)event
{
systemCocoa->handleKeyEvent(event);
}
- (void)flagsChanged:(NSEvent *)event
{
systemCocoa->handleKeyEvent(event);
}
- (void)mouseDown:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)mouseUp:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)rightMouseDown:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)rightMouseUp:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)mouseMoved:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)mouseDragged:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)rightMouseDragged:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)scrollWheel:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)otherMouseDown:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)otherMouseUp:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)otherMouseDragged:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)magnifyWithEvent:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)rotateWithEvent:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)tabletPoint:(NSEvent *)event
{
systemCocoa->handleTabletEvent(event, [event type]);
}
- (void)tabletProximity:(NSEvent *)event
{
systemCocoa->handleTabletEvent(event, [event type]);
}
- (BOOL)isOpaque
{
return YES;
}
- (void)drawRect:(NSRect)rect
{
if ([self inLiveResize]) {
/* Don't redraw while in live resize */
}
else {
[super drawRect:rect];
systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);
/* For some cases like entering fullscreen we need to redraw immediately
* so our window does not show blank during the animation */
if (associatedWindow->getImmediateDraw())
systemCocoa->dispatchEvents();
}
}
// Text input
- (void)composing_free
{
composing = NO;
if (composing_text) {
[composing_text release];
composing_text = nil;
}
}
- (void)insertText:(id)chars
{
[self composing_free];
}
- (void)setMarkedText:(id)chars selectedRange:(NSRange)range
{
[self composing_free];
if ([chars length] == 0)
return;
// start composing
composing = YES;
composing_text = [chars copy];
// if empty, cancel
if ([composing_text length] == 0)
[self composing_free];
}
- (void)unmarkText
{
[self composing_free];
}
- (BOOL)hasMarkedText
{
return (composing) ? YES : NO;
}
- (void)doCommandBySelector:(SEL)selector
{
}
- (BOOL)isComposing
{
return composing;
}
- (NSInteger)conversationIdentifier
{
return (NSInteger)self;
}
- (NSAttributedString *)attributedSubstringFromRange:(NSRange)range
{
return [NSAttributedString new]; // XXX does this leak?
}
- (NSRange)markedRange
{
unsigned int length = (composing_text) ? [composing_text length] : 0;
if (composing)
return NSMakeRange(0, length);
return NSMakeRange(NSNotFound, 0);
}
- (NSRange)selectedRange
{
unsigned int length = (composing_text) ? [composing_text length] : 0;
return NSMakeRange(0, length);
}
- (NSRect)firstRectForCharacterRange:(NSRange)range
{
return NSZeroRect;
}
- (NSUInteger)characterIndexForPoint:(NSPoint)point
{
return NSNotFound;
}
- (NSArray *)validAttributesForMarkedText
{
return [NSArray array]; // XXX does this leak?
}
@end
/* NSView for handling input and drawing. */
#include "GHOST_WindowViewCocoa.h"
#pragma mark initialization / finalization
@ -533,12 +280,13 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(GHOST_SystemCocoa *systemCocoa,
const bool stereoVisual,
bool is_debug)
: GHOST_Window(width, height, state, stereoVisual, false),
m_openGLView(nil),
m_systemCocoa(systemCocoa),
m_customCursor(0),
m_immediateDraw(false),
m_debug_context(is_debug)
{
m_systemCocoa = systemCocoa;
m_fullScreen = false;
m_immediateDraw = false;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@ -602,8 +350,8 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(GHOST_SystemCocoa *systemCocoa,
[m_window setAcceptsMouseMovedEvents:YES];
NSView *view = [m_window contentView];
[view setAcceptsTouchEvents:YES];
NSView *contentview = [m_window contentView];
[contentview setAcceptsTouchEvents:YES];
[m_window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,
NSStringPboardType,

View file

@ -0,0 +1,275 @@
/*
* 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.
*/
/* NSView subclass for drawing and handling input. */
// We need to subclass it in order to give Cocoa the feeling key events are trapped
@interface CocoaOpenGLView : NSOpenGLView <NSTextInput>
{
GHOST_SystemCocoa *systemCocoa;
GHOST_WindowCocoa *associatedWindow;
bool composing;
NSString *composing_text;
bool immediate_draw;
}
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa
windowCocoa:(GHOST_WindowCocoa *)winCocoa;
@end
@implementation CocoaOpenGLView
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa
windowCocoa:(GHOST_WindowCocoa *)winCocoa
{
systemCocoa = sysCocoa;
associatedWindow = winCocoa;
composing = false;
composing_text = nil;
immediate_draw = false;
}
- (BOOL)acceptsFirstResponder
{
return YES;
}
// The trick to prevent Cocoa from complaining (beeping)
- (void)keyDown:(NSEvent *)event
{
systemCocoa->handleKeyEvent(event);
/* Start or continue composing? */
if ([[event characters] length] == 0 || [[event charactersIgnoringModifiers] length] == 0 ||
composing) {
composing = YES;
// interpret event to call insertText
NSMutableArray *events;
events = [[NSMutableArray alloc] initWithCapacity:1];
[events addObject:event];
[self interpretKeyEvents:events]; // calls insertText
[events removeObject:event];
[events release];
return;
}
}
- (void)keyUp:(NSEvent *)event
{
systemCocoa->handleKeyEvent(event);
}
- (void)flagsChanged:(NSEvent *)event
{
systemCocoa->handleKeyEvent(event);
}
- (void)mouseDown:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)mouseUp:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)rightMouseDown:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)rightMouseUp:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)mouseMoved:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)mouseDragged:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)rightMouseDragged:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)scrollWheel:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)otherMouseDown:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)otherMouseUp:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)otherMouseDragged:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)magnifyWithEvent:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)rotateWithEvent:(NSEvent *)event
{
systemCocoa->handleMouseEvent(event);
}
- (void)tabletPoint:(NSEvent *)event
{
systemCocoa->handleTabletEvent(event, [event type]);
}
- (void)tabletProximity:(NSEvent *)event
{
systemCocoa->handleTabletEvent(event, [event type]);
}
- (BOOL)isOpaque
{
return YES;
}
- (void)drawRect:(NSRect)rect
{
if ([self inLiveResize]) {
/* Don't redraw while in live resize */
}
else {
[super drawRect:rect];
systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);
/* For some cases like entering fullscreen we need to redraw immediately
* so our window does not show blank during the animation */
if (associatedWindow->getImmediateDraw())
systemCocoa->dispatchEvents();
}
}
// Text input
- (void)composing_free
{
composing = NO;
if (composing_text) {
[composing_text release];
composing_text = nil;
}
}
- (void)insertText:(id)chars
{
[self composing_free];
}
- (void)setMarkedText:(id)chars selectedRange:(NSRange)range
{
[self composing_free];
if ([chars length] == 0)
return;
// start composing
composing = YES;
composing_text = [chars copy];
// if empty, cancel
if ([composing_text length] == 0)
[self composing_free];
}
- (void)unmarkText
{
[self composing_free];
}
- (BOOL)hasMarkedText
{
return (composing) ? YES : NO;
}
- (void)doCommandBySelector:(SEL)selector
{
}
- (BOOL)isComposing
{
return composing;
}
- (NSInteger)conversationIdentifier
{
return (NSInteger)self;
}
- (NSAttributedString *)attributedSubstringFromRange:(NSRange)range
{
return [NSAttributedString new]; // XXX does this leak?
}
- (NSRange)markedRange
{
unsigned int length = (composing_text) ? [composing_text length] : 0;
if (composing)
return NSMakeRange(0, length);
return NSMakeRange(NSNotFound, 0);
}
- (NSRange)selectedRange
{
unsigned int length = (composing_text) ? [composing_text length] : 0;
return NSMakeRange(0, length);
}
- (NSRect)firstRectForCharacterRange:(NSRange)range
{
return NSZeroRect;
}
- (NSUInteger)characterIndexForPoint:(NSPoint)point
{
return NSNotFound;
}
- (NSArray *)validAttributesForMarkedText
{
return [NSArray array]; // XXX does this leak?
}
@end