From 2f751c75e25a4fd106f8629b0d010391e7d22e32 Mon Sep 17 00:00:00 2001 From: fuzzard Date: Wed, 29 Sep 2021 18:58:28 +1000 Subject: [osx] relocate more SDL specific code --- cmake/treedata/osx/subdirs.txt | 1 + xbmc/platform/darwin/osx/CMakeLists.txt | 2 - xbmc/platform/darwin/osx/OSXTextInputResponder.h | 19 --- xbmc/platform/darwin/osx/OSXTextInputResponder.mm | 185 --------------------- xbmc/platform/darwin/osx/SDL/CMakeLists.txt | 9 + .../darwin/osx/SDL/OSXTextInputResponder.h | 19 +++ .../darwin/osx/SDL/OSXTextInputResponder.mm | 185 +++++++++++++++++++++ xbmc/windowing/osx/SDL/WinSystemOSXSDL.mm | 2 +- 8 files changed, 215 insertions(+), 207 deletions(-) delete mode 100644 xbmc/platform/darwin/osx/OSXTextInputResponder.h delete mode 100644 xbmc/platform/darwin/osx/OSXTextInputResponder.mm create mode 100644 xbmc/platform/darwin/osx/SDL/CMakeLists.txt create mode 100644 xbmc/platform/darwin/osx/SDL/OSXTextInputResponder.h create mode 100644 xbmc/platform/darwin/osx/SDL/OSXTextInputResponder.mm diff --git a/cmake/treedata/osx/subdirs.txt b/cmake/treedata/osx/subdirs.txt index b9fc36e5cb..abc1d9036d 100644 --- a/cmake/treedata/osx/subdirs.txt +++ b/cmake/treedata/osx/subdirs.txt @@ -6,6 +6,7 @@ xbmc/platform/darwin/osx platform/osx xbmc/platform/darwin/osx/network platform/darwin/osx/network xbmc/platform/darwin/osx/peripherals platform/osx/peripherals xbmc/platform/darwin/osx/powermanagement platform/darwin/osx/powermanagement +xbmc/platform/darwin/osx/SDL platform/osx/SDL xbmc/platform/darwin/osx/storage platform/osx/storage xbmc/platform/darwin/peripherals platform/darwin/peripherals xbmc/platform/darwin/utils platform/darwin/utils diff --git a/xbmc/platform/darwin/osx/CMakeLists.txt b/xbmc/platform/darwin/osx/CMakeLists.txt index 3ef7dc54d6..125135b610 100644 --- a/xbmc/platform/darwin/osx/CMakeLists.txt +++ b/xbmc/platform/darwin/osx/CMakeLists.txt @@ -1,7 +1,6 @@ set(SOURCES CocoaInterface.mm CPUInfoOsx.cpp HotKeyController.m - OSXTextInputResponder.mm PlatformDarwinOSX.cpp smc.c XBMCHelper.cpp) @@ -9,7 +8,6 @@ set(SOURCES CocoaInterface.mm set(HEADERS CocoaInterface.h CPUInfoOsx.h HotKeyController.h - OSXTextInputResponder.h PlatformDarwinOSX.h smc.h XBMCHelper.h) diff --git a/xbmc/platform/darwin/osx/OSXTextInputResponder.h b/xbmc/platform/darwin/osx/OSXTextInputResponder.h deleted file mode 100644 index 0448bdbd09..0000000000 --- a/xbmc/platform/darwin/osx/OSXTextInputResponder.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2005-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#import - -@interface OSXTextInputResponder : NSView -{ - NSString *_markedText; - NSRange _markedRange; - NSRange _selectedRange; - NSRect _inputRect; -} -- (void) setInputRect:(NSRect) rect; -@end diff --git a/xbmc/platform/darwin/osx/OSXTextInputResponder.mm b/xbmc/platform/darwin/osx/OSXTextInputResponder.mm deleted file mode 100644 index 0f87beb96a..0000000000 --- a/xbmc/platform/darwin/osx/OSXTextInputResponder.mm +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2005-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#import "OSXTextInputResponder.h" - -#include "GUIUserMessages.h" -#include "ServiceBroker.h" -#include "guilib/GUIWindowManager.h" -#include "input/Key.h" -#include "messaging/ApplicationMessenger.h" -#include "utils/log.h" - -void SendKeyboardText(const char *text) -{ - // CLog::Log(LOGDEBUG, "SendKeyboardText({})", text); - - /* Don't post text events for unprintable characters */ - if ((unsigned char)*text < ' ' || *text == 127) - return; - - CAction *action = new CAction(ACTION_INPUT_TEXT); - action->SetText(text); - CServiceBroker::GetAppMessenger()->PostMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1, - static_cast(action)); -} - -void SendEditingText(const char *text, unsigned int location, unsigned int length) -{ - //@todo fix this hack - // CLog::Log(LOGDEBUG, "SendEditingText({}, {}, {})", text, location, length); - // CGUIMessage msg(GUI_MSG_INPUT_TEXT_EDIT, 0, 0, location, length); - // msg.SetLabel(text); - // CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg, CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindowOrDialog()); -} - -@implementation OSXTextInputResponder - -- (id)initWithFrame:(NSRect)frame -{ - self = [super initWithFrame:frame]; - if (self) { - // Initialization code here. - _selectedRange = NSMakeRange(0, 0); - _markedRange = NSMakeRange(NSNotFound, 0); - _inputRect = NSZeroRect; - } - - return self; -} - -- (void) setInputRect:(NSRect) rect -{ - _inputRect = rect; -} - -- (void) insertText:(id) aString replacementRange:(NSRange)replacementRange -{ - const char *str; - - if (replacementRange.location == NSNotFound) { - if (_markedRange.location != NSNotFound) { - replacementRange = _markedRange; - } else { - replacementRange = _selectedRange; - } - } - - /* Could be NSString or NSAttributedString, so we have - * to test and convert it */ - if ([aString isKindOfClass: [NSAttributedString class]]) - str = [[aString string] UTF8String]; - else - str = [aString UTF8String]; - - SendKeyboardText(str); - - [self unmarkText]; -} - -- (void) doCommandBySelector:(SEL) myselector -{ - // No need to do anything since we are not using Cocoa - // selectors to handle special keys, instead we use SDL - // key events to do the same job. -} - -- (BOOL) hasMarkedText -{ - return _markedText != nil; -} - -- (NSRange) markedRange -{ - return _markedRange; -} - -- (NSRange) selectedRange -{ - return _selectedRange; -} - -- (void) setMarkedText:(id) aString - selectedRange:(NSRange) selRange - replacementRange:(NSRange) replacementRange -{ - if (replacementRange.location == NSNotFound) { - if (_markedRange.location != NSNotFound) - replacementRange = _markedRange; - else - replacementRange = _selectedRange; - } - - if ([aString isKindOfClass: [NSAttributedString class]]) - aString = [aString string]; - - if ([aString length] == 0) - { - [self unmarkText]; - return; - } - - _markedText = aString; - _selectedRange = selRange; -// _markedRange = NSMakeRange(0, [aString length]); - _markedRange = NSMakeRange(replacementRange.location, [aString length]); - - SendEditingText([aString UTF8String], selRange.location, selRange.length); -} - -- (void) unmarkText -{ - _markedText = nil; - _markedRange = NSMakeRange(NSNotFound, 0); - - SendEditingText("", 0, 0); -} - -- (NSRect) firstRectForCharacterRange: (NSRange) theRange - actualRange:(NSRangePointer)actualRange -{ - if (actualRange) - *actualRange = theRange; - - NSWindow *window = [self window]; - NSRect contentRect = [window contentRectForFrameRect: [window frame]]; - double windowHeight = contentRect.size.height; - NSRect rect = NSMakeRect(_inputRect.origin.x, windowHeight - _inputRect.origin.y - _inputRect.size.height, - _inputRect.size.width, _inputRect.size.height); - - // CLog::Log(LOGDEBUG, "firstRectForCharacterRange: ({}, {}): windowHeight = {}, rect = {}", - // theRange.location, theRange.length, windowHeight, - // [NSStringFromRect(rect) UTF8String]); - rect.origin = [[self window] convertRectToScreen:rect].origin; - - return rect; -} - -- (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)theRange - actualRange:(NSRangePointer)actualRange -{ - return nil; -} - -// This method returns the index for character that is -// nearest to thePoint. thPoint is in screen coordinate system. -- (NSUInteger) characterIndexForPoint:(NSPoint) thePoint -{ - return 0; -} - -// This method is the key to attribute extension. -// We could add new attributes through this method. -// NSInputServer examines the return value of this -// method & constructs appropriate attributed string. -- (NSArray *) validAttributesForMarkedText -{ - return [NSArray array]; -} - -@end diff --git a/xbmc/platform/darwin/osx/SDL/CMakeLists.txt b/xbmc/platform/darwin/osx/SDL/CMakeLists.txt new file mode 100644 index 0000000000..a9badcf8c6 --- /dev/null +++ b/xbmc/platform/darwin/osx/SDL/CMakeLists.txt @@ -0,0 +1,9 @@ +if(SDL_FOUND) + set(SOURCES OSXTextInputResponder.mm) + + set(HEADERS OSXTextInputResponder.h) +endif() + +if(SOURCES) + core_add_library(platform_osx_SDL) +endif() diff --git a/xbmc/platform/darwin/osx/SDL/OSXTextInputResponder.h b/xbmc/platform/darwin/osx/SDL/OSXTextInputResponder.h new file mode 100644 index 0000000000..0448bdbd09 --- /dev/null +++ b/xbmc/platform/darwin/osx/SDL/OSXTextInputResponder.h @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#import + +@interface OSXTextInputResponder : NSView +{ + NSString *_markedText; + NSRange _markedRange; + NSRange _selectedRange; + NSRect _inputRect; +} +- (void) setInputRect:(NSRect) rect; +@end diff --git a/xbmc/platform/darwin/osx/SDL/OSXTextInputResponder.mm b/xbmc/platform/darwin/osx/SDL/OSXTextInputResponder.mm new file mode 100644 index 0000000000..0f87beb96a --- /dev/null +++ b/xbmc/platform/darwin/osx/SDL/OSXTextInputResponder.mm @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2005-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#import "OSXTextInputResponder.h" + +#include "GUIUserMessages.h" +#include "ServiceBroker.h" +#include "guilib/GUIWindowManager.h" +#include "input/Key.h" +#include "messaging/ApplicationMessenger.h" +#include "utils/log.h" + +void SendKeyboardText(const char *text) +{ + // CLog::Log(LOGDEBUG, "SendKeyboardText({})", text); + + /* Don't post text events for unprintable characters */ + if ((unsigned char)*text < ' ' || *text == 127) + return; + + CAction *action = new CAction(ACTION_INPUT_TEXT); + action->SetText(text); + CServiceBroker::GetAppMessenger()->PostMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1, + static_cast(action)); +} + +void SendEditingText(const char *text, unsigned int location, unsigned int length) +{ + //@todo fix this hack + // CLog::Log(LOGDEBUG, "SendEditingText({}, {}, {})", text, location, length); + // CGUIMessage msg(GUI_MSG_INPUT_TEXT_EDIT, 0, 0, location, length); + // msg.SetLabel(text); + // CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg, CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindowOrDialog()); +} + +@implementation OSXTextInputResponder + +- (id)initWithFrame:(NSRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + // Initialization code here. + _selectedRange = NSMakeRange(0, 0); + _markedRange = NSMakeRange(NSNotFound, 0); + _inputRect = NSZeroRect; + } + + return self; +} + +- (void) setInputRect:(NSRect) rect +{ + _inputRect = rect; +} + +- (void) insertText:(id) aString replacementRange:(NSRange)replacementRange +{ + const char *str; + + if (replacementRange.location == NSNotFound) { + if (_markedRange.location != NSNotFound) { + replacementRange = _markedRange; + } else { + replacementRange = _selectedRange; + } + } + + /* Could be NSString or NSAttributedString, so we have + * to test and convert it */ + if ([aString isKindOfClass: [NSAttributedString class]]) + str = [[aString string] UTF8String]; + else + str = [aString UTF8String]; + + SendKeyboardText(str); + + [self unmarkText]; +} + +- (void) doCommandBySelector:(SEL) myselector +{ + // No need to do anything since we are not using Cocoa + // selectors to handle special keys, instead we use SDL + // key events to do the same job. +} + +- (BOOL) hasMarkedText +{ + return _markedText != nil; +} + +- (NSRange) markedRange +{ + return _markedRange; +} + +- (NSRange) selectedRange +{ + return _selectedRange; +} + +- (void) setMarkedText:(id) aString + selectedRange:(NSRange) selRange + replacementRange:(NSRange) replacementRange +{ + if (replacementRange.location == NSNotFound) { + if (_markedRange.location != NSNotFound) + replacementRange = _markedRange; + else + replacementRange = _selectedRange; + } + + if ([aString isKindOfClass: [NSAttributedString class]]) + aString = [aString string]; + + if ([aString length] == 0) + { + [self unmarkText]; + return; + } + + _markedText = aString; + _selectedRange = selRange; +// _markedRange = NSMakeRange(0, [aString length]); + _markedRange = NSMakeRange(replacementRange.location, [aString length]); + + SendEditingText([aString UTF8String], selRange.location, selRange.length); +} + +- (void) unmarkText +{ + _markedText = nil; + _markedRange = NSMakeRange(NSNotFound, 0); + + SendEditingText("", 0, 0); +} + +- (NSRect) firstRectForCharacterRange: (NSRange) theRange + actualRange:(NSRangePointer)actualRange +{ + if (actualRange) + *actualRange = theRange; + + NSWindow *window = [self window]; + NSRect contentRect = [window contentRectForFrameRect: [window frame]]; + double windowHeight = contentRect.size.height; + NSRect rect = NSMakeRect(_inputRect.origin.x, windowHeight - _inputRect.origin.y - _inputRect.size.height, + _inputRect.size.width, _inputRect.size.height); + + // CLog::Log(LOGDEBUG, "firstRectForCharacterRange: ({}, {}): windowHeight = {}, rect = {}", + // theRange.location, theRange.length, windowHeight, + // [NSStringFromRect(rect) UTF8String]); + rect.origin = [[self window] convertRectToScreen:rect].origin; + + return rect; +} + +- (NSAttributedString*)attributedSubstringForProposedRange:(NSRange)theRange + actualRange:(NSRangePointer)actualRange +{ + return nil; +} + +// This method returns the index for character that is +// nearest to thePoint. thPoint is in screen coordinate system. +- (NSUInteger) characterIndexForPoint:(NSPoint) thePoint +{ + return 0; +} + +// This method is the key to attribute extension. +// We could add new attributes through this method. +// NSInputServer examines the return value of this +// method & constructs appropriate attributed string. +- (NSArray *) validAttributesForMarkedText +{ + return [NSArray array]; +} + +@end diff --git a/xbmc/windowing/osx/SDL/WinSystemOSXSDL.mm b/xbmc/windowing/osx/SDL/WinSystemOSXSDL.mm index 08cccfc14f..bec2de98db 100644 --- a/xbmc/windowing/osx/SDL/WinSystemOSXSDL.mm +++ b/xbmc/windowing/osx/SDL/WinSystemOSXSDL.mm @@ -40,7 +40,7 @@ #include "platform/darwin/DarwinUtils.h" #include "platform/darwin/DictionaryUtils.h" #include "platform/darwin/osx/CocoaInterface.h" -#import "platform/darwin/osx/OSXTextInputResponder.h" +#import "platform/darwin/osx/SDL/OSXTextInputResponder.h" #include "platform/darwin/osx/XBMCHelper.h" #include -- cgit v1.2.3